protected override void OnHandle(IPacket packet, ClientWorldState worldState) { NewItemPacket incomingPacket = (NewItemPacket)packet; if (incomingPacket.ItemId == 0) { return; } Item item = worldState.GetItem(incomingPacket.ItemId); if (item == null) { ItemModel itemData = NetworkEngine.Instance.LoadItem(incomingPacket.ItemId); item = worldState.CreateItem(itemData); worldState.AddItem(item); } }
public bool LoadContent(ClientWorldState world) { if (!this.CharacterSelected) { worldServerClient.Disconnect(); return(false); } //CharacterData playerCharData = dataContext.GetCharacter(playerSelectableCharacter); IEnumerable <ItemModel> items = dataContext.GetItems(playerSelectableCharacter.MapId); if (items != null) { List <Item> hasContainerItem = new List <Item>(); foreach (ItemModel itemData in items) { Item item = world.CreateItem(itemData); if (item.ContainerId.HasValue) { hasContainerItem.Add(item); } world.AddItem(item); } foreach (Item item in hasContainerItem) { ContainerItem containerItem = (ContainerItem)world.GetItem(item.ContainerId.Value); if (containerItem != null) { containerItem.Items.Add(item); } } } //world.PlayerCharacter = new ClientCharacter(playerCharacterId, playerCharData.WorldLocation); ////world.PlayerCharacter.Id = playerCharacterId; //world.PlayerCharacter.Health = playerCharData.Health; //world.PlayerCharacter.Energy = playerCharData.Energy; //world.PlayerCharacter.InventoryData = dataContext.GetItem(playerCharData.InventoryID); //world.PlayerCharacter.Inventory = (BagClientItem)world.CreateItem(world.PlayerCharacter.InventoryData); //world.AddCharacter(world.PlayerCharacter); //world.AddItem(world.PlayerCharacter.Inventory); IEnumerable <CharacterModel> onlineCharacters = dataContext.GetCharacters(playerSelectableCharacter.MapId); if (onlineCharacters != null) { foreach (CharacterModel charData in onlineCharacters) { ClientCharacter character = world.CreateCharacter(charData); //, dataContext.GetItem(charData.InventoryID)); //new ClientCharacter(charData.CharacterDataID, charData.WorldLocation); ////world.PlayerCharacter.Id = playerCharacterId; //character.Health = playerCharData.Health; //character.Energy = playerCharData.Energy; //character.InventoryData = dataContext.GetItem(charData.InventoryID); //if (character.InventoryData != null) // character.Inventory = (BagClientItem)world.CreateItem(character.InventoryData); if (character.Id == playerSelectableCharacter.CharacterId) { world.PlayerCharacter = character; } if (character != null) { world.AddCharacter(character); } //world.AddItem(character.Inventory); } } if (world.PlayerCharacter == null) { worldServerClient.Disconnect(); return(false); } return(true); }