//============================================================================
// control/server/misc/item.cs
//  Copyright (c) 2003, 2005 by Kenneth C.  Finney.
//============================================================================
$RespawnDelay = 20000;
$LoiterDelay = 10000;
function Item::Respawn(%this)
{
   %this.StartFade(0, 0, true);
   %this.setHidden(true);
   // Schedule a resurrection
   %this.Schedule($RespawnDelay, "Hide", false);
   %this.Schedule($RespawnDelay + 10, "StartFade", 3000, 0, false);
}
function Item::SchedulePop(%this)
{
   %this.Schedule($LoiterDelay - 1000, "StartFade", 3000, 0, true);
   %this.Schedule($LoiterDelay, "Delete");
}
function ItemData::OnThrow(%this,%user,%amount)
{
   // Remove the object from the inventory
   if (%amount $= "")
      %amount = 1;
   if (%this.maxInventory !$= "")
      if (%amount > %this.maxInventory)
         %amount = %this.maxInventory;
   if (!%amount)
      return 0;
   %user.DecInventory(%this,%amount);
   %obj = new Item() {
      datablock = %this;
      rotation = "0 0 1 " @ (GetRandom() * 360);
      count = %amount;
   };
   MissionGroup.Add(%obj);
   %obj.SchedulePop();
   return %obj;
}
function ItemData::OnPickup(%this,%obj,%user,%amount)
{
   %count = %obj.count;
   if (%count $= "")
      if (%this.maxInventory !$= "") {
         if (!(%count = %this.maxInventory))
            return;
      }
      else
         %count = 1;
   %user.IncInventory(%this,%count);
   if (%user.client)
      MessageClient(%user.client, 'MsgItemPickup', '\c0You picked up %1', %this.pickupName);
   if (%obj.IsStatic())
      %obj.Respawn();
   else
      %obj.Delete();
   return true;
}
function ItemData::Create(%data)
{
   %obj = new Item() {
      dataBlock = %data;
      static = true;
      rotate = true;
   };
   return %obj;
}
datablock ItemData(Copper)
{
   category = "Coins";
   // Basic Item properties
   shapeFile = "~/data/models/items/kash1.dts";
   mass = 0.7;
   friction = 0.8;
   elasticity = 0.3;
   respawnTime = 30 * 60000;
   salvageTime = 15 * 60000;
   // Dynamic properties defined by the scripts
   pickupName = "a copper coin";
   value = 1;
};
datablock ItemData(Silver)
{
   category = "Coins";
   // Basic Item properties
   shapeFile = "~/data/models/items/kash100.dts";
   mass = 0.7;
   friction = 0.8;
   elasticity = 0.3;
   respawnTime = 30 * 60000;
   salvageTime = 15 * 60000;
   // Dynamic properties defined by the scripts
   pickupName = "a silver coin";
   value = 100;
};
datablock ItemData(Gold)
{
   category = "Coins";

   // Basic Item properties
   shapeFile = "~/data/models/items/kash1000.dts";
   mass = 0.7;
   friction = 0.8;
   elasticity = 0.3;
   respawnTime = 30 * 60000;
   salvageTime = 15 * 60000;
   // Dynamic properties defined by the scripts
   pickupName = "a gold coin";
   value = 1000;
};
datablock ItemData(FirstAidKit)
{
   category = "Health";
   // Basic Item properties
   shapeFile = "~/data/models/items/healthPatch.dts";
   mass = 1;
   friction = 1;
   elasticity = 0.3;
   respawnTime = 600000;
   // Dynamic properties defined by the scripts
   repairAmount = 200;
   maxInventory = 0; // No pickup or throw
};
function FirstAidKit::onCollision(%this,%obj,%col)
{
   if (%col.getDamageLevel() != 0 && %col.getState() !$= "Dead" )
   {
      %col.applyRepair(%this.repairAmount);
      %obj.respawn();
      if (%col.client)
      {
         messageClient
              (%col.client,'MSG_Treatment','\c2Medical treatment applied');
      }
   }
}
