private void InitCaches() { if (cacheUICharacterHotkeys == null) { cacheUICharacterHotkeys = new Dictionary <string, List <UICharacterHotkey> >(); foreach (var uiCharacterHotkey in uiCharacterHotkeys) { var id = uiCharacterHotkey.hotkeyId; var ui = uiCharacterHotkey.ui; if (!string.IsNullOrEmpty(id) && ui != null) { var characterHotkey = new CharacterHotkey(); characterHotkey.hotkeyId = id; characterHotkey.type = HotkeyType.None; characterHotkey.dataId = 0; ui.Setup(characterHotkey, -1); if (!cacheUICharacterHotkeys.ContainsKey(id)) { cacheUICharacterHotkeys.Add(id, new List <UICharacterHotkey>()); } cacheUICharacterHotkeys[id].Add(ui); } } } }
public void GetObjectData(System.Object obj, SerializationInfo info, StreamingContext context) { CharacterHotkey data = (CharacterHotkey)obj; info.AddValue("hotkeyId", data.hotkeyId); info.AddValue("type", (byte)data.type); info.AddValue("dataId", data.dataId); }
public void CreateCharacterHotkey(string characterId, CharacterHotkey characterHotkey) { ExecuteNonQuery("INSERT INTO characterhotkey (id, characterId, hotkeyId, type, dataId) VALUES (@id, @characterId, @hotkeyId, @type, @dataId)", new SqliteParameter("@id", characterId + "_" + characterHotkey.hotkeyId), new SqliteParameter("@characterId", characterId), new SqliteParameter("@hotkeyId", characterHotkey.hotkeyId), new SqliteParameter("@type", characterHotkey.type), new SqliteParameter("@dataId", characterHotkey.dataId)); }
public System.Object SetObjectData(System.Object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector) { CharacterHotkey data = (CharacterHotkey)obj; data.hotkeyId = info.GetString("hotkeyId"); data.type = (HotkeyType)info.GetByte("type"); data.dataId = info.GetInt32("dataId"); obj = data; return(obj); }
public override void UseHotkey(int hotkeyIndex) { if (hotkeyIndex < 0 || hotkeyIndex >= PlayerCharacterEntity.Hotkeys.Count) { return; } CancelBuild(); buildingItemIndex = -1; CurrentBuildingEntity = null; CharacterHotkey hotkey = PlayerCharacterEntity.Hotkeys[hotkeyIndex]; Skill skill = hotkey.GetSkill(); if (skill != null) { short skillLevel; if (PlayerCharacterEntity.CacheSkills.TryGetValue(skill, out skillLevel)) { if (skill.CanUse(PlayerCharacterEntity, skillLevel)) { PlayerCharacterEntity.StopMove(); queueSkill = skill; } } } Item item = hotkey.GetItem(); if (item != null) { int itemIndex = PlayerCharacterEntity.IndexOfNonEquipItem(item.DataId); if (itemIndex >= 0) { if (item.IsEquipment()) { PlayerCharacterEntity.RequestEquipItem((short)itemIndex); } else if (item.IsPotion() || item.IsPet()) { PlayerCharacterEntity.RequestUseItem((short)itemIndex); } else if (item.IsBuilding()) { PlayerCharacterEntity.StopMove(); buildingItemIndex = itemIndex; CurrentBuildingEntity = Instantiate(item.buildingEntity); CurrentBuildingEntity.SetupAsBuildMode(); CurrentBuildingEntity.CacheTransform.parent = null; } } } }
private bool ReadCharacterHotkey(MySqlDataReader reader, out CharacterHotkey result) { if (reader.Read()) { result = new CharacterHotkey(); result.hotkeyId = reader.GetString(0); result.type = (HotkeyType)reader.GetByte(1); result.relateId = reader.GetString(2); return(true); } result = CharacterHotkey.Empty; return(false); }
public void SetHotKeys(BuildHotKey[] hotKeys) { List <CharacterHotkey> set = new List <CharacterHotkey>(); foreach (BuildHotKey hotKey in hotKeys) { CharacterHotkey characterHotkey = new CharacterHotkey(); characterHotkey.type = hotKey.type; characterHotkey.relateId = hotKey.relateId; characterHotkey.hotkeyId = hotKey.hotkeyId; set.Add(characterHotkey); } Hotkeys = set; }
private bool ReadCharacterHotkey(MySQLRowsReader reader, out CharacterHotkey result, bool resetReader = true) { if (resetReader) { reader.ResetReader(); } if (reader.Read()) { result = new CharacterHotkey(); result.hotkeyId = reader.GetString("hotkeyId"); result.type = (HotkeyType)reader.GetSByte("type"); result.relateId = reader.GetString("relateId"); return(true); } result = CharacterHotkey.Empty; return(false); }
protected virtual void NetFuncAssignHotkey(string hotkeyId, byte type, int dataId) { CharacterHotkey characterHotkey = new CharacterHotkey(); characterHotkey.hotkeyId = hotkeyId; characterHotkey.type = (HotkeyType)type; characterHotkey.dataId = dataId; int hotkeyIndex = this.IndexOfHotkey(hotkeyId); if (hotkeyIndex >= 0) { hotkeys[hotkeyIndex] = characterHotkey; } else { hotkeys.Add(characterHotkey); } }
public void UpdateData(IPlayerCharacterData character) { this.character = character; InitCaches(); IList <CharacterHotkey> characterHotkeys = character.Hotkeys; for (int i = 0; i < characterHotkeys.Count; ++i) { CharacterHotkey characterHotkey = characterHotkeys[i]; List <UICharacterHotkey> uis; if (!string.IsNullOrEmpty(characterHotkey.hotkeyId) && CacheUICharacterHotkeys.TryGetValue(characterHotkey.hotkeyId, out uis)) { foreach (UICharacterHotkey ui in uis) { ui.Setup(this, characterHotkey, i); ui.Show(); } } } }
private void InitCaches() { if (cacheUICharacterHotkeys == null) { SelectionManager.DeselectSelectedUI(); SelectionManager.Clear(); var j = 0; cacheUICharacterHotkeys = new Dictionary <string, List <UICharacterHotkey> >(); for (var i = 0; i < uiCharacterHotkeys.Length; ++i) { var uiCharacterHotkey = uiCharacterHotkeys[i]; var id = uiCharacterHotkey.hotkeyId; var ui = uiCharacterHotkey.ui; if (!string.IsNullOrEmpty(id) && ui != null) { var characterHotkey = new CharacterHotkey(); characterHotkey.hotkeyId = id; characterHotkey.type = HotkeyType.None; characterHotkey.dataId = 0; ui.Setup(characterHotkey, -1); if (!cacheUICharacterHotkeys.ContainsKey(id)) { cacheUICharacterHotkeys.Add(id, new List <UICharacterHotkey>()); } cacheUICharacterHotkeys[id].Add(ui); SelectionManager.Add(ui); // Select first UI if (j == 0) { ui.OnClickSelect(); } ++j; } } } }
public void CreateCharacterHotkey(MySqlConnection connection, MySqlTransaction transaction, string characterId, CharacterHotkey characterHotkey) { ExecuteNonQuery(connection, transaction, "INSERT INTO characterhotkey (id, characterId, hotkeyId, type, relateId) VALUES (@id, @characterId, @hotkeyId, @type, @relateId)", new MySqlParameter("@id", characterId + "_" + characterHotkey.hotkeyId), new MySqlParameter("@characterId", characterId), new MySqlParameter("@hotkeyId", characterHotkey.hotkeyId), new MySqlParameter("@type", characterHotkey.type), new MySqlParameter("@relateId", characterHotkey.relateId)); }
public static T DeserializeCharacterData <T>(this T characterData, NetDataReader reader) where T : IPlayerCharacterData { var tempCharacterData = new PlayerCharacterData(); tempCharacterData.Id = reader.GetString(); tempCharacterData.DataId = reader.GetInt(); tempCharacterData.EntityId = reader.GetInt(); tempCharacterData.CharacterName = reader.GetString(); tempCharacterData.Level = reader.GetShort(); tempCharacterData.Exp = reader.GetInt(); tempCharacterData.CurrentHp = reader.GetInt(); tempCharacterData.CurrentMp = reader.GetInt(); tempCharacterData.CurrentStamina = reader.GetInt(); tempCharacterData.CurrentFood = reader.GetInt(); tempCharacterData.CurrentWater = reader.GetInt(); tempCharacterData.StatPoint = reader.GetShort(); tempCharacterData.SkillPoint = reader.GetShort(); tempCharacterData.Gold = reader.GetInt(); tempCharacterData.PartyId = reader.GetInt(); tempCharacterData.GuildId = reader.GetInt(); tempCharacterData.GuildRole = reader.GetByte(); tempCharacterData.SharedGuildExp = reader.GetInt(); tempCharacterData.CurrentMapName = reader.GetString(); tempCharacterData.CurrentPosition = new Vector3(reader.GetFloat(), reader.GetFloat(), reader.GetFloat()); tempCharacterData.RespawnMapName = reader.GetString(); tempCharacterData.RespawnPosition = new Vector3(reader.GetFloat(), reader.GetFloat(), reader.GetFloat()); tempCharacterData.LastUpdate = reader.GetInt(); int count = 0; count = reader.GetByte(); for (var i = 0; i < count; ++i) { var entry = new CharacterAttribute(); entry.Deserialize(reader); tempCharacterData.Attributes.Add(entry); } count = reader.GetByte(); for (var i = 0; i < count; ++i) { var entry = new CharacterBuff(); entry.Deserialize(reader); tempCharacterData.Buffs.Add(entry); } count = reader.GetByte(); for (var i = 0; i < count; ++i) { var entry = new CharacterSkill(); entry.Deserialize(reader); tempCharacterData.Skills.Add(entry); } count = reader.GetByte(); for (var i = 0; i < count; ++i) { var entry = new CharacterSkillUsage(); entry.Deserialize(reader); tempCharacterData.SkillUsages.Add(entry); } count = reader.GetByte(); for (var i = 0; i < count; ++i) { var entry = new CharacterSummon(); entry.Deserialize(reader); tempCharacterData.Summons.Add(entry); } count = reader.GetByte(); for (var i = 0; i < count; ++i) { var entry = new CharacterItem(); entry.Deserialize(reader); tempCharacterData.EquipItems.Add(entry); } count = reader.GetShort(); for (var i = 0; i < count; ++i) { var entry = new CharacterItem(); entry.Deserialize(reader); tempCharacterData.NonEquipItems.Add(entry); } count = reader.GetByte(); for (var i = 0; i < count; ++i) { var entry = new CharacterHotkey(); entry.Deserialize(reader); tempCharacterData.Hotkeys.Add(entry); } count = reader.GetByte(); for (var i = 0; i < count; ++i) { var entry = new CharacterQuest(); entry.Deserialize(reader); tempCharacterData.Quests.Add(entry); } var equipWeapons = new EquipWeapons(); equipWeapons.Deserialize(reader); tempCharacterData.EquipWeapons = equipWeapons; DevExtUtils.InvokeStaticDevExtMethods(ClassType, "DeserializeCharacterData", characterData, reader); tempCharacterData.ValidateCharacterData(); tempCharacterData.CloneTo(characterData); return(characterData); }
public override void UseHotkey(int hotkeyIndex) { if (hotkeyIndex < 0 || hotkeyIndex >= PlayerCharacterEntity.Hotkeys.Count) { return; } CancelBuild(); buildingItemIndex = -1; CurrentBuildingEntity = null; CharacterHotkey hotkey = PlayerCharacterEntity.Hotkeys[hotkeyIndex]; Skill skill = hotkey.GetSkill(); if (skill != null) { short skillLevel; if (PlayerCharacterEntity.CacheSkills.TryGetValue(skill, out skillLevel)) { BaseCharacterEntity attackingCharacter; if (TryGetAttackingCharacter(out attackingCharacter)) { // If attacking any character, will use skill later queueUsingSkill = new UsingSkillData(null, skill.DataId); } else if (skill.CanUse(PlayerCharacterEntity, skillLevel)) { // If not attacking any character, use skill immediately if (skill.IsAttack()) { if (IsLockTarget()) { // If attacking any character, will use skill later queueUsingSkill = new UsingSkillData(null, skill.DataId); if (SelectedEntity != null && SelectedEntity is BaseCharacterEntity) { // Attacking selected target PlayerCharacterEntity.SetTargetEntity(SelectedEntity); } else { // Attacking nearest target BaseCharacterEntity nearestTarget = PlayerCharacterEntity.FindNearestAliveCharacter <BaseCharacterEntity>(PlayerCharacterEntity.GetSkillAttackDistance(skill, isLeftHandAttacking) + lockAttackTargetDistance, false, true, false); if (nearestTarget != null) { PlayerCharacterEntity.SetTargetEntity(nearestTarget); } } } else { // Not lock target, use it immediately destination = null; PlayerCharacterEntity.StopMove(); PlayerCharacterEntity.RequestUseSkill(skill.DataId, isLeftHandAttacking); isLeftHandAttacking = !isLeftHandAttacking; } } else { // This is not attack skill, use it immediately destination = null; PlayerCharacterEntity.StopMove(); PlayerCharacterEntity.RequestUseSkill(skill.DataId, isLeftHandAttacking); } } } } Item item = hotkey.GetItem(); if (item != null) { int itemIndex = PlayerCharacterEntity.IndexOfNonEquipItem(item.DataId); if (itemIndex >= 0) { if (item.IsEquipment()) { RequestEquipItem((short)itemIndex); } else if (item.IsPotion() || item.IsPet()) { RequestUseItem((short)itemIndex); } else if (item.IsBuilding()) { destination = null; PlayerCharacterEntity.StopMove(); buildingItemIndex = itemIndex; CurrentBuildingEntity = Instantiate(item.buildingEntity); CurrentBuildingEntity.SetupAsBuildMode(); CurrentBuildingEntity.CacheTransform.parent = null; FindAndSetBuildingAreaFromCharacterDirection(); } } } }
public static bool IsEmpty(this CharacterHotkey data) { return(data == null || data.Equals(CharacterHotkey.Empty)); }