private void _statsList(DisplayStats _data) { CharStatData localStats = World.Instance.MainPlayer.ActiveCharacter.Stats; if (_data.IsStatsData) { localStats.statpoints = _data.StatPoints; } else { World.Instance.MainPlayer.ActiveCharacter.Class = _data.Class; } localStats.SetStr(_data.Str); localStats.SetInt(_data.Int); localStats.SetWis(_data.Wis); localStats.SetAgi(_data.Agi); localStats.SetCon(_data.Con); localStats.SetCha(_data.Cha); localStats.SetMaxHP(_data.MaxHP); localStats.SetMaxTP(_data.MaxTP); localStats.SetSP(_data.MaxSP); localStats.SetMaxSP(_data.MaxSP); World.Instance.MainPlayer.ActiveCharacter.MaxWeight = _data.MaxWeight; localStats.SetMinDam(_data.MinDam); localStats.SetMaxDam(_data.MaxDam); localStats.SetAccuracy(_data.Accuracy); localStats.SetEvade(_data.Evade); localStats.SetArmor(_data.Armor); m_game.Hud.RefreshStats(); }
private void _useItem(ItemUseData data) { World.Instance.MainPlayer.ActiveCharacter.UpdateInventoryItem(data.ItemID, data.CharacterAmount, data.Weight, data.MaxWeight); switch (data.Type) { case ItemType.Teleport: /*Warp packet handles the rest!*/ break; case ItemType.Heal: { World.Instance.MainPlayer.ActiveCharacter.Stats.SetHP(data.HP); World.Instance.MainPlayer.ActiveCharacter.Stats.SetTP(data.TP); int percent = (int)Math.Round(100.0 * ((double)data.HP / World.Instance.MainPlayer.ActiveCharacter.Stats.maxhp)); if (data.HPGain > 0) { World.Instance.ActiveCharacterRenderer.SetDamageCounterValue(data.HPGain, percent, true); } m_game.Hud.RefreshStats(); } break; case ItemType.HairDye: { World.Instance.MainPlayer.ActiveCharacter.RenderData.SetHairColor(data.HairColor); } break; case ItemType.Beer: World.Instance.ActiveCharacterRenderer.MakeDrunk(); m_game.Hud.SetStatusLabel(DATCONST2.STATUS_LABEL_TYPE_WARNING, DATCONST2.STATUS_LABEL_ITEM_USE_DRUNK); break; case ItemType.EffectPotion: { //World.Instance.ActiveCharacterRenderer.ShowEffect(data.EffectID); //todo: get effects working } break; case ItemType.CureCurse: { //actually remove the item(s) from the main character Character c = World.Instance.MainPlayer.ActiveCharacter; for (int i = 0; i < (int)EquipLocation.PAPERDOLL_MAX; ++i) { int nextID = c.PaperDoll[i]; if (nextID > 0 && World.Instance.EIF.GetItemRecordByID(nextID).Special == ItemSpecial.Cursed) { c.PaperDoll[i] = 0; switch ((EquipLocation)i) { case EquipLocation.Boots: c.RenderData.SetBoots(0); break; case EquipLocation.Armor: c.RenderData.SetArmor(0); break; case EquipLocation.Hat: c.RenderData.SetHat(0); break; case EquipLocation.Shield: c.RenderData.SetShield(0); break; case EquipLocation.Weapon: c.RenderData.SetWeapon(0); break; } } } //update main character's stats CharStatData s = c.Stats; s.SetMaxHP(data.CureStats.MaxHP); s.SetMaxTP(data.CureStats.MaxTP); s.SetStr(data.CureStats.Str); s.SetInt(data.CureStats.Int); s.SetWis(data.CureStats.Wis); s.SetAgi(data.CureStats.Agi); s.SetCon(data.CureStats.Con); s.SetCha(data.CureStats.Cha); s.SetMinDam(data.CureStats.MinDam); s.SetMaxDam(data.CureStats.MaxDam); s.SetAccuracy(data.CureStats.Accuracy); s.SetEvade(data.CureStats.Evade); s.SetArmor(data.CureStats.Armor); m_game.Hud.RefreshStats(); } break; case ItemType.EXPReward: { CharStatData s = World.Instance.MainPlayer.ActiveCharacter.Stats; if (s.level < data.RewardStats.Level) { //level up! World.Instance.MainPlayer.ActiveCharacter.Emote(Emote.LevelUp); World.Instance.ActiveCharacterRenderer.PlayerEmote(); s.level = data.RewardStats.Level; } s.exp = data.RewardStats.Exp; s.statpoints = data.RewardStats.StatPoints; s.skillpoints = data.RewardStats.SkillPoints; s.maxhp = data.RewardStats.MaxHP; s.maxtp = data.RewardStats.MaxTP; s.maxsp = data.RewardStats.MaxSP; } break; } }
private void _setupPacketAPIEventHandlers() { m_packetAPI.OnWarpRequestNewMap += World.Instance.CheckMap; m_packetAPI.OnWarpAgree += World.Instance.WarpAgreeAction; m_packetAPI.OnPlayerEnterMap += (_data, _anim) => World.Instance.ActiveMapRenderer.AddOtherPlayer(_data, _anim); m_packetAPI.OnNPCEnterMap += _data => World.Instance.ActiveMapRenderer.AddOtherNPC(_data); m_packetAPI.OnMainPlayerWalk += _list => { foreach (var item in _list) { World.Instance.ActiveMapRenderer.AddMapItem(item); } }; m_packetAPI.OnOtherPlayerWalk += (a, b, c, d) => World.Instance.ActiveMapRenderer.OtherPlayerWalk(a, b, c, d); m_packetAPI.OnAdminHiddenChange += (id, hidden) => { if (World.Instance.MainPlayer.ActiveCharacter.ID == id) { World.Instance.MainPlayer.ActiveCharacter.RenderData.SetHidden(hidden); } else { World.Instance.ActiveMapRenderer.OtherPlayerHide(id, hidden); } }; m_packetAPI.OnOtherPlayerAttack += (id, dir) => World.Instance.ActiveMapRenderer.OtherPlayerAttack(id, dir); m_packetAPI.OnPlayerAvatarRemove += (id, anim) => World.Instance.ActiveMapRenderer.RemoveOtherPlayer(id, anim); m_packetAPI.OnPlayerAvatarChange += _data => { switch (_data.Slot) { case AvatarSlot.Clothes: World.Instance.ActiveMapRenderer.UpdateOtherPlayer(_data.ID, _data.Sound, new CharRenderData { boots = _data.Boots, armor = _data.Armor, hat = _data.Hat, shield = _data.Shield, weapon = _data.Weapon }); break; case AvatarSlot.Hair: World.Instance.ActiveMapRenderer.UpdateOtherPlayer(_data.ID, _data.HairColor, _data.HairStyle); break; case AvatarSlot.HairColor: World.Instance.ActiveMapRenderer.UpdateOtherPlayer(_data.ID, _data.HairColor); break; } }; m_packetAPI.OnPlayerPaperdollChange += _data => { Character c; if (!_data.ItemWasUnequipped) { ItemRecord rec = World.Instance.EIF.GetItemRecordByID(_data.ItemID); //update inventory (c = World.Instance.MainPlayer.ActiveCharacter).UpdateInventoryItem(_data.ItemID, _data.ItemAmount); //equip item c.EquipItem(rec.Type, (short)rec.ID, (short)rec.DollGraphic, true, (sbyte)_data.SubLoc); //add to paperdoll dialog if (EOPaperdollDialog.Instance != null) { EOPaperdollDialog.Instance.SetItem(rec.GetEquipLocation() + _data.SubLoc, rec); } } else { c = World.Instance.MainPlayer.ActiveCharacter; //update inventory c.UpdateInventoryItem(_data.ItemID, 1, true); //true: add to existing quantity //unequip item c.UnequipItem(World.Instance.EIF.GetItemRecordByID(_data.ItemID).Type, _data.SubLoc); } c.UpdateStatsAfterEquip(_data); }; m_packetAPI.OnViewPaperdoll += _data => { if (EOPaperdollDialog.Instance != null) { return; } Character c; if (World.Instance.MainPlayer.ActiveCharacter.ID == _data.PlayerID) { //paperdoll requested for main player, all info should be up to date c = World.Instance.MainPlayer.ActiveCharacter; Array.Copy(_data.Paperdoll.ToArray(), c.PaperDoll, (int)EquipLocation.PAPERDOLL_MAX); } else { if ((c = World.Instance.ActiveMapRenderer.GetOtherPlayer(_data.PlayerID)) != null) { c.Class = _data.Class; c.RenderData.SetGender(_data.Gender); c.Title = _data.Title; c.GuildName = _data.Guild; Array.Copy(_data.Paperdoll.ToArray(), c.PaperDoll, (int)EquipLocation.PAPERDOLL_MAX); } } if (c != null) { EOPaperdollDialog.Show(m_packetAPI, c, _data); } }; m_packetAPI.OnDoorOpen += (x, y) => World.Instance.ActiveMapRenderer.OnDoorOpened(x, y); m_packetAPI.OnChestOpened += data => { if (EOChestDialog.Instance == null || data.X != EOChestDialog.Instance.CurrentChestX || data.Y != EOChestDialog.Instance.CurrentChestY) { return; } EOChestDialog.Instance.InitializeItems(data.Items); }; m_packetAPI.OnChestAgree += data => EOChestDialog.Instance.InitializeItems(data.Items); m_packetAPI.OnChestAddItem += (id, amount, weight, maxWeight, data) => { World.Instance.MainPlayer.ActiveCharacter.UpdateInventoryItem(id, amount, weight, maxWeight); EOChestDialog.Instance.InitializeItems(data.Items); Hud.RefreshStats(); }; m_packetAPI.OnChestGetItem += (id, amount, weight, maxWeight, data) => { World.Instance.MainPlayer.ActiveCharacter.UpdateInventoryItem(id, amount, weight, maxWeight); EOChestDialog.Instance.InitializeItems(data.Items); Hud.RefreshStats(); }; m_packetAPI.OnServerPingReply += timeout => Hud.AddChat(ChatTabs.Local, "System", string.Format("[x] Current ping to the server is: {0} ms.", timeout), ChatType.LookingDude); m_packetAPI.OnPlayerFace += (playerId, dir) => World.Instance.ActiveMapRenderer.OtherPlayerFace(playerId, dir); m_packetAPI.OnPlayerFindCommandReply += (online, sameMap, charName) => { if (charName.Length == 0) { return; } string lastPart; if (online && !sameMap) { lastPart = World.GetString(DATCONST2.STATUS_LABEL_IS_ONLINE_IN_THIS_WORLD); } else if (online) { lastPart = World.GetString(DATCONST2.STATUS_LABEL_IS_ONLINE_SAME_MAP); } else { lastPart = World.GetString(DATCONST2.STATUS_LABEL_IS_ONLINE_NOT_FOUND); } Hud.AddChat(ChatTabs.Local, "System", string.Format("{0} " + lastPart, char.ToUpper(charName[0]) + charName.Substring(1)), ChatType.LookingDude); }; m_packetAPI.OnPlayerRecover += (hp, tp) => { World.Instance.MainPlayer.ActiveCharacter.Stats.SetHP(hp); World.Instance.MainPlayer.ActiveCharacter.Stats.SetTP(tp); Hud.RefreshStats(); }; m_packetAPI.OnRecoverReply += (exp, karma, level) => { World.Instance.MainPlayer.ActiveCharacter.Stats.exp = exp; World.Instance.MainPlayer.ActiveCharacter.Stats.karma = karma; if (level > 0) { World.Instance.MainPlayer.ActiveCharacter.Stats.level = level; } Hud.RefreshStats(); }; m_packetAPI.OnRecoverStatList += _data => { CharStatData localStats = World.Instance.MainPlayer.ActiveCharacter.Stats; World.Instance.MainPlayer.ActiveCharacter.Class = _data.Class; localStats.SetStr(_data.Str); localStats.SetInt(_data.Int); localStats.SetWis(_data.Wis); localStats.SetAgi(_data.Agi); localStats.SetCon(_data.Con); localStats.SetCha(_data.Cha); localStats.SetMaxHP(_data.MaxHP); localStats.SetMaxTP(_data.MaxTP); localStats.SetMaxSP(_data.MaxSP); World.Instance.MainPlayer.ActiveCharacter.MaxWeight = _data.MaxWeight; localStats.SetMinDam(_data.MinDam); localStats.SetMaxDam(_data.MaxDam); localStats.SetAccuracy(_data.Accuracy); localStats.SetEvade(_data.Evade); localStats.SetArmor(_data.Armor); Hud.RefreshStats(); }; m_packetAPI.OnPlayerHeal += (playerID, hpGain, playerPctHealth) => World.Instance.ActiveMapRenderer.OtherPlayerHeal(playerID, hpGain, playerPctHealth); m_packetAPI.OnGetItemFromMap += (uid, id, amountTaken, weight, maxWeight) => { if (uid != 0) //$si command has uid of 0 since we're creating a new item from nothing { World.Instance.ActiveMapRenderer.UpdateMapItemAmount(uid, amountTaken); } World.Instance.MainPlayer.ActiveCharacter.UpdateInventoryItem(id, amountTaken, weight, maxWeight, true); ItemRecord rec = World.Instance.EIF.GetItemRecordByID(id); Hud.AddChat(ChatTabs.System, "", string.Format("{0} {1} {2}", World.GetString(DATCONST2.STATUS_LABEL_ITEM_PICKUP_YOU_PICKED_UP), amountTaken, rec.Name), ChatType.UpArrow); Hud.SetStatusLabel(DATCONST2.STATUS_LABEL_TYPE_INFORMATION, DATCONST2.STATUS_LABEL_ITEM_PICKUP_YOU_PICKED_UP, string.Format(" {0} {1}", amountTaken, rec.Name)); }; m_packetAPI.OnRemoveItemFromMap += uid => World.Instance.ActiveMapRenderer.RemoveMapItem(uid); m_packetAPI.OnJunkItem += (id, amountRemoved, amountRemaining, weight, maxWeight) => { World.Instance.MainPlayer.ActiveCharacter.UpdateInventoryItem(id, amountRemaining, weight, maxWeight); ItemRecord rec = World.Instance.EIF.GetItemRecordByID(id); Hud.AddChat(ChatTabs.System, "", string.Format("{0} {1} {2}", World.GetString(DATCONST2.STATUS_LABEL_ITEM_JUNK_YOU_JUNKED), amountRemoved, rec.Name), ChatType.DownArrow); Hud.SetStatusLabel(DATCONST2.STATUS_LABEL_TYPE_INFORMATION, DATCONST2.STATUS_LABEL_ITEM_JUNK_YOU_JUNKED, string.Format(" {0} {1}", amountRemoved, rec.Name)); }; m_packetAPI.OnDropItem += (characterAmount, weight, maxWeight, item) => { World.Instance.ActiveMapRenderer.AddMapItem(item); if (characterAmount >= 0) //will be -1 when another player drops { World.Instance.MainPlayer.ActiveCharacter.UpdateInventoryItem(item.id, characterAmount, weight, maxWeight); ItemRecord rec = World.Instance.EIF.GetItemRecordByID(item.id); Hud.AddChat(ChatTabs.System, "", string.Format("{0} {1} {2}", World.GetString(DATCONST2.STATUS_LABEL_ITEM_DROP_YOU_DROPPED), item.amount, rec.Name), ChatType.DownArrow); Hud.SetStatusLabel(DATCONST2.STATUS_LABEL_TYPE_INFORMATION, DATCONST2.STATUS_LABEL_ITEM_DROP_YOU_DROPPED, string.Format(" {0} {1}", item.amount, rec.Name)); } }; m_packetAPI.OnUseItem += data => { World.Instance.MainPlayer.ActiveCharacter.UpdateInventoryItem(data.ItemID, data.CharacterAmount, data.Weight, data.MaxWeight); switch (data.Type) { case ItemType.Teleport: /*Warp packet handles the rest!*/ break; case ItemType.Heal: { World.Instance.MainPlayer.ActiveCharacter.Stats.SetHP(data.HP); World.Instance.MainPlayer.ActiveCharacter.Stats.SetTP(data.TP); int percent = (int)Math.Round(100.0 * ((double)data.HP / World.Instance.MainPlayer.ActiveCharacter.Stats.maxhp)); if (data.HPGain > 0) { World.Instance.ActiveCharacterRenderer.SetDamageCounterValue(data.HPGain, percent, true); } Hud.RefreshStats(); } break; case ItemType.HairDye: { World.Instance.MainPlayer.ActiveCharacter.RenderData.SetHairColor(data.HairColor); } break; case ItemType.Beer: World.Instance.ActiveCharacterRenderer.MakeDrunk(); Hud.SetStatusLabel(DATCONST2.STATUS_LABEL_TYPE_WARNING, DATCONST2.STATUS_LABEL_ITEM_USE_DRUNK); break; case ItemType.EffectPotion: { //World.Instance.ActiveCharacterRenderer.ShowEffect(data.EffectID); //todo: get effects working } break; case ItemType.CureCurse: { //actually remove the item(s) from the main character Character c = World.Instance.MainPlayer.ActiveCharacter; for (int i = 0; i < (int)EquipLocation.PAPERDOLL_MAX; ++i) { int nextID = c.PaperDoll[i]; if (nextID > 0 && World.Instance.EIF.GetItemRecordByID(nextID).Special == ItemSpecial.Cursed) { c.PaperDoll[i] = 0; switch ((EquipLocation)i) { case EquipLocation.Boots: c.RenderData.SetBoots(0); break; case EquipLocation.Armor: c.RenderData.SetArmor(0); break; case EquipLocation.Hat: c.RenderData.SetHat(0); break; case EquipLocation.Shield: c.RenderData.SetShield(0); break; case EquipLocation.Weapon: c.RenderData.SetWeapon(0); break; } } } //update main character's stats CharStatData s = c.Stats; s.SetMaxHP(data.CureStats.MaxHP); s.SetMaxTP(data.CureStats.MaxTP); s.SetStr(data.CureStats.Str); s.SetInt(data.CureStats.Int); s.SetWis(data.CureStats.Wis); s.SetAgi(data.CureStats.Agi); s.SetCon(data.CureStats.Con); s.SetCha(data.CureStats.Cha); s.SetMinDam(data.CureStats.MinDam); s.SetMaxDam(data.CureStats.MaxDam); s.SetAccuracy(data.CureStats.Accuracy); s.SetEvade(data.CureStats.Evade); s.SetArmor(data.CureStats.Armor); Hud.RefreshStats(); } break; case ItemType.EXPReward: { CharStatData s = World.Instance.MainPlayer.ActiveCharacter.Stats; if (s.level < data.RewardStats.Level) { //level up! World.Instance.MainPlayer.ActiveCharacter.Emote(Emote.LevelUp); World.Instance.ActiveCharacterRenderer.PlayerEmote(); s.level = data.RewardStats.Level; } s.exp = data.RewardStats.Exp; s.statpoints = data.RewardStats.StatPoints; s.skillpoints = data.RewardStats.SkillPoints; s.maxhp = data.RewardStats.MaxHP; s.maxtp = data.RewardStats.MaxTP; s.maxsp = data.RewardStats.MaxSP; } break; } }; m_packetAPI.OnMapMutation += () => { if (File.Exists("maps\\00000.emf")) { string fmt = string.Format("maps\\{0,5:D5}.emf", World.Instance.MainPlayer.ActiveCharacter.CurrentMap); if (File.Exists(fmt)) { File.Delete(fmt); } File.Move("maps\\00000.emf", fmt); World.Instance.Remap(); } else { throw new FileNotFoundException("Unable to remap the file, something broke"); } }; }