public static PlayerSkill CreateInstanceFromSaveData(PlayerSkillData data) { PlayerSkill result = data.prototype.CreateCopy(); result.useCount = data.useCount; return(result); }
/// <summary> /// 技能可解锁在本地判断,服务器只负责验证; /// </summary> void skillOpenChecker(int lv) { PlayerDataModule pdm = ModuleManager.Instance.FindModule <PlayerDataModule>(); if (pdm == null) { return; } PlayerSkillData skillData = null; IDictionaryEnumerator itr = DataManager.SkillLearnTable.GetEnumerator(); while (itr.MoveNext()) { SkillLearnTableItem item = itr.Value as SkillLearnTableItem; if (item == null) { continue; } if (lv < item.unlock_lv) { continue; } skillData = pdm.GetSkillData(); if (skillData == null || skillData.mLevels.ContainsKey(item.id)) { continue; } pdm.UpdateSkillData(item.id, 0); } }
public PlayerSkillData GetSaveData() { PlayerSkillData res = new PlayerSkillData(); res.prototype = prototype; res.useCount = useCount; return(res); }
public override void Initialize() { Instance = this; AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => { var path = Path.Combine("Nugets", args.Name.Substring(0, args.Name.IndexOf(",")) + ".dll"); if (File.Exists(path)) { return(Assembly.LoadFrom(path)); } return(null); }; Config = StarverConfig.Read(ConfigPath); Skills = new SkillManager(); PlayerDatas = new PlayerDataManager(StorageType.MySql); Players = new StarverPlayer[TShock.Players.Length]; #region Test #if false var data = new PlayerData(-444) { Level = 3 }; var skills = new PlayerSkillData[5]; skills[0] = new PlayerSkillData { ID = (byte)SkillIDs.LawAias, BindByProj = true, BindID = ProjectileID.Spear }; data.SetSkillDatas(skills); PlayerDatas.SaveData(data); #endif #endregion #region Hooks ServerApi.Hooks.ServerJoin.Register(this, OnJoin); ServerApi.Hooks.ServerLeave.Register(this, OnLeave); ServerApi.Hooks.NpcStrike.Register(this, OnNpcStrike); ServerApi.Hooks.GameUpdate.Register(this, OnUpdate); ServerApi.Hooks.NetGetData.Register(this, OnGetData); TShockAPI.Hooks.PlayerHooks.PlayerPostLogin += OnPostLogin; GetDataHandlers.NewProjectile += OnNewProjectile; #endregion #region Commands Commands.ChatCommands.Add(new Command(Perms.Normal, MainCommand, "starver")); Commands.ChatCommands.Add(new Command(Perms.Aura.Normal, AuraCommand, "aura", "au")); #endregion }
/// <summary> /// 根据SkillID判断,该技能在技能槽中的位置[0...3] /// falseult < 0 表示不存在; /// </summary> /// <returns>The slot index by skill I.</returns> public bool GetSlotIdxBySkillID(int skillID, ref int slotIdx) { PlayerData pd = PlayerDataPool.Instance.MainData; if (pd == null) { Debug.LogError("MainData is Null"); return(false); } PlayerSkillData skillData = pd.skillData; slotIdx = -1; for (int i = 0, j = skillData.skills.Length; i < j; i++) { if (skillData.skills[i] == skillID) { slotIdx = i; return(true); } } return(false); }
public PlayerSkillData() { Instance = this; }
/// <summary> /// 装备/切换技能; /// idx : 技能槽索引[1,4]; /// skillId : 技能Id; /// </summary> public void EquipSkill(int idx, int skillId) { PlayerData pd = PlayerDataPool.Instance.MainData; if (pd == null) { Debug.LogError("MainData is Null"); return; } if (idx < 1 || idx > SkillMaxCountDefine.MAX_EQUIP_SKILL_NUM) { Debug.LogError("技能槽索引值无效"); return; } if (IsSlotLocked(idx)) { Debug.LogError("技能槽还没有解锁,装备技能失败"); return; } PlayerSkillData skillData = pd.skillData; idx -= 1; //要装备的技能在技能槽中存在且在技能槽中的位置不变,不做操作; if (skillData.skills[idx] == skillId) { return; } int[] skillIds = new int[4]; skillIds = skillData.skills; int slotIdx = -1; if (!GetSlotIdxBySkillID(skillId, ref slotIdx)) { skillIds[idx] = skillId; } //如果要装备的技能在技能槽中存在,在技能槽的位置改变,那么互换该技能原来位置和现在的技能槽的位置; else { int temp = skillData.skills[idx]; skillIds[idx] = skillId; skillIds[slotIdx] = temp; } SkillEquipActionParam param = new SkillEquipActionParam(); param.EquipIdx = skillIds; Net.Instance.DoAction((int)MESSAGE_ID.ID_MSG_SKILL, param); #region //int slotIdx = -1; ////记录哪个位置的技能槽发生改变; //ArrayList changeIdx = new ArrayList(); ////记录哪个位置的技能发生改变; //ArrayList changeSkillIdx = new ArrayList(); ////要装备的技能在技能槽中不存在,直接替换为该技能; //if(!GetSlotIdxBySkillID(skillId , ref slotIdx)) //{ // changeSkillIdx.Clear(); // changeSkillIdx.Add(skillId); // changeSkillIdx.Add(skillData.skills[idx]); // skillData.skills[idx] = skillId; // changeIdx.Clear(); // changeIdx.Add(idx); //} ////如果要装备的技能在技能槽中存在,在技能槽的位置改变,那么互换该技能原来位置和现在的技能槽的位置; //else //{ // int temp = skillData.skills[idx]; // skillData.skills[idx] = skillId; // skillData.skills[slotIdx] = temp; // changeIdx.Clear(); // changeIdx.Add(idx); // changeIdx.Add(slotIdx); // changeSkillIdx.Clear(); // changeSkillIdx.Add(temp); // changeSkillIdx.Add(skillId); //} //SkillUIEvent se = new SkillUIEvent(SkillUIEvent.SKILL_SLOT_CHANGE); //se.msg = changeIdx;//记录的slotIdx有效范围[0...3] //EventSystem.Instance.PushEvent(se); //SkillUIEvent se1 = new SkillUIEvent(SkillUIEvent.SKILL_LIST_CHANGE); //se1.msg = changeSkillIdx; //EventSystem.Instance.PushEvent(se1); #endregion }
void Start() { StartCoroutine(RecordNearbyEnemyToArray()); playerSkillData = new PlayerSkillData(); }