public Netwearable MakeNetWear() { var netCopy = new Netwearable(); netCopy.Inlitialize(this); return(netCopy); }
public override void Initialize(NetItem item) { base.Initialize(item); Netwearable wear = item as Netwearable; Space = wear.Space; Type = wear.Type; }
public static void JsonObject(Packet packet) { int id = packet.ReadInt(); if (!GameManager.players.ContainsKey(id)) { return; } string json = packet.ReadString(); JsonSerializerSettings settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }; NetEntity jsonObj = JsonConvert.DeserializeObject <NetEntity>(json, settings); if (jsonObj is NetAnimator) { GameManager.players[id].Animator.Set(jsonObj as NetAnimator); return; } if (jsonObj is BuildingData) { GameManager.instance.SpawnStructure(jsonObj as BuildingData); return; } if (jsonObj is NetItem) { NetItem netItem = jsonObj as NetItem; if (netItem is Netwearable) { Netwearable netWear = netItem as Netwearable; Wearable wear = new Wearable(); wear.Initialize(netWear); GameManager.instance.ChangeInventory(id, wear); } if (netItem is NetHoldable) { NetHoldable netHold = netItem as NetHoldable; Holdable hold = new Holdable(); hold.Initialize(netHold); GameManager.instance.ChangeInventory(id, hold); } return; } if (jsonObj is NetLoot) { NetLoot netLoot = jsonObj as NetLoot; GameManager.instance.CheckLoot(netLoot); } if (jsonObj is NetInventory) { Debug.Log("update inventory"); } }
public static void ChangeWearable(int player, Netwearable wearable) { using (Packet packet = new Packet((int)ServerPackets.jsonObject)) { packet.Write(player); JsonSerializerSettings settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All, ReferenceLoopHandling = ReferenceLoopHandling.Ignore }; string json = JsonConvert.SerializeObject(wearable, settings); packet.Write(json); SendTCPDataToAll(packet); } }
public void SendSwapRequest(RuntimeItem newWear, RuntimeItem oldWear) { Debug.Log("Send swap wear request to server: " + newWear.Item.Name); JsonSerializerSettings settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All, ReferenceLoopHandling = ReferenceLoopHandling.Ignore }; Netwearable netItem = newWear.Item.MakeNetWear(); Netwearable netItemOld = oldWear.Item.MakeNetWear(); string newWearjson = JsonConvert.SerializeObject(netItem, settings); string oldWearjson = JsonConvert.SerializeObject(netItemOld, settings); ClientSend.SendJsonPackage(newWearjson); ClientSend.SendJsonPackage(oldWearjson); }
public static void JsonPackate(int fromPlayer, Packet packet) { int id = packet.ReadInt(); string json = packet.ReadString(); JsonSerializerSettings settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }; NetEntity netPackage = JsonConvert.DeserializeObject <NetEntity>(json, settings); if (netPackage is BuildingData) { NetworkManager.instance.ConstructionControl.BuildBuilding(id, (BuildingData)netPackage); } if (netPackage is NetItem) { NetItem netItem = netPackage as NetItem; if (netItem is Netwearable) { Netwearable netWear = netItem as Netwearable; NetworkManager.instance.InventoryControl.ChangeWear(netWear, id); } if (netItem is NetHoldable) { NetHoldable netHold = netItem as NetHoldable; Debug.Log($"got holdable: {netHold.Name}"); } } if (netPackage is NetLoot) { NetLoot netLoot = netPackage as NetLoot; if (netLoot.ownerID == -1) { NetworkManager.instance.LootControl.UpdateLoot(netLoot); } else { NetworkManager.instance.InventoryControl.TakeLoot(netLoot); } } }
public void ChangeWear(Netwearable netWear, int id) { Wearable wear = new Wearable(); wear.Initialize(netWear); List <Item> items = new List <Item>(); items.Add(wear as Item); if (netWear.Slot == "Head_Slot" || netWear.Slot == "Torso_Slot" || netWear.Slot == "Legs_Slot" || netWear.Slot == "Right_Arm_Slot" || netWear.Slot == "Left_Arm_Slot") { Debug.Log($"was in wear slot: {netWear.Slot}"); LoadController.instance.LoadRuntimeItems(items, ItemsLoaded); ServerSend.ChangeWearable(id, netWear); return; } LoadController.instance.LoadRuntimeItems(items, ItemsLoaded); Debug.Log($"was NOT in wear slot: {netWear.Slot}"); }
public List <Item> GetItems() { List <Item> items = new List <Item>(); foreach (var item in Items) { if (item is Netwearable) { Netwearable netWear = item as Netwearable; Wearable wearable = new Wearable(); wearable.Initialize(netWear); items.Add(wearable); } if (item is NetHoldable) { NetHoldable netHold = item as NetHoldable; Holdable holdable = new Holdable(); holdable.Initialize(netHold); items.Add(holdable); } if (item is NetConsumable) { NetConsumable netCons = item as NetConsumable; Consumable consumable = new Consumable(); consumable.Initialize(netCons); items.Add(consumable); } if (item is NetMisc) { NetMisc netMisc = item as NetMisc; Misc misc = new Misc(); misc.Initialize(netMisc); items.Add(misc); } } return(items); }