Пример #1
0
 public override void OnEvent(StealItem evnt)
 {
     if (BoltNetwork.isServer && evnt.robbed != LocalPlayer.Entity)
     {
         StealItem stealItem = StealItem.Create(evnt.robbed.source);
         stealItem.thief  = evnt.thief;
         stealItem.robbed = evnt.robbed;
         stealItem.Send();
     }
     else if (evnt.robbed == LocalPlayer.Entity)
     {
         if (!LocalPlayer.Inventory.IsRightHandEmpty())
         {
             ItemStorageProxy component = LocalPlayer.Inventory.RightHand._held.GetComponent <ItemStorageProxy>();
             if (component)
             {
                 for (int i = 0; i < component._storage.UsedSlots.Count; i++)
                 {
                     PlayerAddItem playerAddItem = PlayerAddItem.Create(GlobalTargets.OnlyServer);
                     playerAddItem.Player = evnt.thief;
                     playerAddItem.ItemId = component._storage.UsedSlots[i]._itemId;
                     playerAddItem.Amount = component._storage.UsedSlots[i]._amount;
                     playerAddItem.Send();
                 }
                 component._storage.Close();
                 component._storage.UsedSlots.Clear();
                 component._storage.UpdateContentVersion();
                 component.CheckContentVersion();
             }
             else
             {
                 PlayerAddItem playerAddItem = PlayerAddItem.Create(GlobalTargets.OnlyServer);
                 playerAddItem.Player = evnt.thief;
                 playerAddItem.ItemId = LocalPlayer.Inventory.RightHand._itemId;
                 playerAddItem.Send();
                 LocalPlayer.Inventory.UnequipItemAtSlot(Item.EquipmentSlot.RightHand, false, false, false);
             }
         }
     }
     else if (evnt.robbed.source == LocalPlayer.Entity.source)
     {
         ItemStorage component2 = evnt.robbed.GetComponent <ItemStorage>();
         if (component2)
         {
             for (int j = 0; j < component2.UsedSlots.Count; j++)
             {
                 PlayerAddItem playerAddItem2 = PlayerAddItem.Create(GlobalTargets.OnlyServer);
                 playerAddItem2.Player = evnt.thief;
                 playerAddItem2.ItemId = component2.UsedSlots[j]._itemId;
                 playerAddItem2.Amount = component2.UsedSlots[j]._amount;
                 playerAddItem2.Send();
             }
             BoltNetwork.Destroy(component2.gameObject);
         }
     }
 }
Пример #2
0
 public override void OnEvent(StealItem evnt)
 {
     if (BoltNetwork.isServer && evnt.robbed != LocalPlayer.Entity)
     {
         StealItem stealItem = StealItem.Create(evnt.robbed.source);
         stealItem.thief  = evnt.thief;
         stealItem.robbed = evnt.robbed;
         stealItem.Send();
     }
     else if (evnt.robbed == LocalPlayer.Entity)
     {
         if (!LocalPlayer.Inventory.IsRightHandEmpty())
         {
             ItemStorageProxy component = LocalPlayer.Inventory.RightHand._held.GetComponent <ItemStorageProxy>();
             if (component)
             {
                 for (int i = 0; i < component._storage.UsedSlots.Count; i++)
                 {
                     PlayerAddItem playerAddItem = PlayerAddItem.Create(GlobalTargets.OnlyServer);
                     playerAddItem.Player = evnt.thief;
                     playerAddItem.ItemId = component._storage.UsedSlots[i]._itemId;
                     playerAddItem.Amount = component._storage.UsedSlots[i]._amount;
                     component._storage.UsedSlots[i]._properties.Fill(playerAddItem);
                     playerAddItem.Send();
                     Item item = ItemDatabase.ItemById(playerAddItem.ItemId);
                     if (item.MatchType(Item.Types.Weapon))
                     {
                         EventRegistry.Achievements.Publish(TfEvent.Achievements.SharedWeapon, null);
                     }
                     else if (item.MatchType(Item.Types.Edible))
                     {
                         EventRegistry.Achievements.Publish(TfEvent.Achievements.SharedEdible, null);
                     }
                 }
                 component._storage.Close();
                 component._storage.UsedSlots.Clear();
                 component._storage.UpdateContentVersion();
                 component.CheckContentVersion();
             }
             else
             {
                 PlayerAddItem playerAddItem = PlayerAddItem.Create(GlobalTargets.OnlyServer);
                 playerAddItem.Player = evnt.thief;
                 playerAddItem.ItemId = LocalPlayer.Inventory.RightHand._itemId;
                 LocalPlayer.Inventory.RightHand.Properties.Fill(playerAddItem);
                 playerAddItem.Send();
                 LocalPlayer.Inventory.UnequipItemAtSlot(Item.EquipmentSlot.RightHand, false, false, false);
             }
         }
     }
     else if (evnt.robbed.source == LocalPlayer.Entity.source)
     {
         ItemStorage component2 = evnt.robbed.GetComponent <ItemStorage>();
         if (component2)
         {
             for (int j = 0; j < component2.UsedSlots.Count; j++)
             {
                 PlayerAddItem playerAddItem2 = PlayerAddItem.Create(GlobalTargets.OnlyServer);
                 playerAddItem2.Player = evnt.thief;
                 playerAddItem2.ItemId = component2.UsedSlots[j]._itemId;
                 playerAddItem2.Amount = component2.UsedSlots[j]._amount;
                 playerAddItem2.Send();
             }
             BoltNetwork.Destroy(component2.gameObject);
         }
     }
 }