/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Here we go. Let's define the functions that get called whenever a skill is executed. * This is the place where you wanna start to create your own custom skills. Perhaps some * kind of scripting support will be added in the far future. * */ public static void SkillRequest(int skillID, Database.Player.RACE race, Database.Player pAttacker, int targetID = 0, Map.Nod position = null) { Skill skill = null; Dictionary <int, Skill> dict = null; ActiveSkill activeSkill; if (!pAttacker.activeSkillList.TryGetValue(skillID, out activeSkill)) { throw new KeyNotFoundException(); } try { switch (race) { case Database.Player.RACE.KNIGHT: dict = knightSkillList; break; case Database.Player.RACE.MAGE: dict = mageSkillList; break; case Database.Player.RACE.ARCHER: dict = archerSkillList; break; default: throw new NullReferenceException(); break; } skill = dict[skillID]; } catch (KeyNotFoundException e) { Output.WriteLine("SkillHandler::GetSkillExecuteHandler " + "Someone tried to execute a skill for that no handler exists. " + e.Source.ToString() + " : " + e.TargetSite.ToString()); } catch (NullReferenceException) { // Should never ever happen -.- Output.WriteLine("SkillHandler::GetSkillExecuteHandler " + "Someone tried to request a skill for an unknown race!"); } //This is place where we do actions for requested skill Output.WriteLine("SkillRequest: " + skill.name); if (activeSkill.ElapsedCoolDown() > 0 && activeSkill.ElapsedCoolDown() < skill.coolDown) { Output.WriteLine(ConsoleColor.Red, "SkillHandler::SkillRequest - can't cast skill (still on CoolDown)"); Output.WriteLine(ConsoleColor.Red, "SkillHandler::SkillRequest CoolDown: " + activeSkill.ElapsedCoolDown().ToString()); return; } Output.WriteLine(ConsoleColor.DarkGreen, "SkillHandler::SkillRequest CoolDown: " + activeSkill.ElapsedCoolDown().ToString()); pAttacker.isCastingSkill = true; pAttacker.currentCastingSkillID = skillID; activeSkill.StartCast(); BroadcastPacket bPacket = new BroadcastPacket((uint)pAttacker.PosX, (uint)pAttacker.PosY, (int)World.DEBUG_SIGHT_RANGE, new Packet.SendPacketHandlers.SkillAnim(pAttacker.PlayerPID, targetID, activeSkill.skillID, activeSkill.skillLvl)); GameServer.world.broadcastQueue.Enqueue(bPacket); }
public static void SkillExecute(int skillID, Database.Player.RACE race, Database.Player pAttacker, int targetID = 0, Map.Nod position = null) { if (!pAttacker.isCastingSkill || pAttacker.currentCastingSkillID != skillID) { Output.WriteLine("SkillHandler::SkillExecute " + " Try to cast skill but isCastingSkill is FALSE or skill ID missmatch"); return; // if no Skillrequest executed or player break the skill execute then return } Skill skill = null; Dictionary <int, Skill> dict = null; ActiveSkill activeSkill; if (!pAttacker.activeSkillList.TryGetValue(skillID, out activeSkill)) { throw new KeyNotFoundException(); } try { switch (race) { case Database.Player.RACE.KNIGHT: dict = knightSkillList; break; case Database.Player.RACE.MAGE: dict = mageSkillList; break; case Database.Player.RACE.ARCHER: dict = archerSkillList; break; default: throw new NullReferenceException(); break; } skill = dict[skillID]; } catch (KeyNotFoundException e) { Output.WriteLine("SkillHandler::SkillExecute " + "Someone tried to execute a skill for that no handler exists. " + e.Source.ToString() + " : " + e.TargetSite.ToString()); } catch (NullReferenceException) { // Should never ever happen -.- Output.WriteLine("SkillHandler::SkillExecute " + "Someone tried to request a skill for an unknown race!"); } if (activeSkill.ElapsedCast() > 0 && activeSkill.ElapsedCast() < skill.castTime) { Output.WriteLine(ConsoleColor.Red, "SkillHandler::SkillExecute - can't cast skill (still in cast time)"); Output.WriteLine(ConsoleColor.Red, "SkillHandler::SkillExecute cast time: " + activeSkill.ElapsedCast().ToString()); return; } Output.WriteLine(ConsoleColor.DarkGreen, "SkillHandler::SkillExecute cast time: " + activeSkill.ElapsedCast().ToString()); //this is place where we do actions for execution the skill Output.WriteLine("SkillExecute: " + skill.name); Output.WriteLine("cast time: " + skill.castTime); Output.WriteLine("cool down: " + skill.coolDown); Output.WriteLine("info: " + skill.info); Output.WriteLine("lvl: " + skill.lvl); Output.WriteLine("mana cost: " + skill.manaCost); Output.WriteLine("race: " + skill.race); Output.WriteLine("range: " + skill.range); activeSkill.StartCoolDown(); activeSkill.startCast = DateTime.UtcNow; pAttacker.isCastingSkill = false; pAttacker.currentCastingSkillID = -1; //BroadcastPacket bPacket = new BroadcastPacket((uint)pAttacker.PosX, (uint)pAttacker.PosY, (int)World.DEBUG_SIGHT_RANGE, new Packet.SendPacketHandlers.AttackMag(pAttacker.PlayerPID, targetID, activeSkill.skillID, activeSkill.skillLvl)); //GameServer.world.broadcastQueue.Enqueue(bPacket); switch (skill.demageFlag) { //skills that need to give target entity case SKILL_DEMAGE_FLAG.SINGLE_TARGET_FLAG: case SKILL_DEMAGE_FLAG.MULTI_TARGET_FLAG: { Action act = new Action(activeSkill, skill, pAttacker, targetID); GameServer.world.actions.Enqueue(act); Output.WriteLine("Skill enqueue as target skill"); } break; //skills that are place related not target entity case SKILL_DEMAGE_FLAG.POSITION_TARGET_FLAG: case SKILL_DEMAGE_FLAG.CON_45_FLAG: case SKILL_DEMAGE_FLAG.CON_90_FLAG: case SKILL_DEMAGE_FLAG.AOE_TARGET_FLAG: { Action act = new Action(activeSkill, skill, pAttacker, position); GameServer.world.actions.Enqueue(act); Output.WriteLine("Skill enqueue as position skill"); } break; default: Output.WriteLine("Skill has inncorrect DEMAGE FLAG SET"); break; } }
//Load all skills for every race static bool ReadIniFile(string fileName, Database.Player.RACE race) { //its only to force static constructor to execute Dictionary <int, Skill> skillList = null; switch (race) { case Database.Player.RACE.KNIGHT: skillList = knightSkillList; Output.WriteLine(ConsoleColor.Cyan, "Begin register skills for KNIGHT"); break; case Database.Player.RACE.MAGE: skillList = mageSkillList; Output.WriteLine(ConsoleColor.Cyan, "Begin register skills for MAGE"); break; case Database.Player.RACE.ARCHER: skillList = archerSkillList; Output.WriteLine(ConsoleColor.Cyan, "Begin register skills for ARCHER"); break; } IniFile configServerFile = new IniFile(fileName); foreach (string sec in configServerFile.Sections) { Skill sk = new Skill(); string tmp; sk.name = sec; sk.skillID = configServerFile.GetInteger(sec, "id", 0); sk.lvl = configServerFile.GetInteger(sec, "lvl", 1); sk.coolDown = configServerFile.GetInteger(sec, "coolDown", 0); sk.castTime = configServerFile.GetInteger(sec, "castTime", 0); sk.info = configServerFile.GetValue(sec, "info", "null"); sk.range = configServerFile.GetInteger(sec, "range", 1); //to faster the math in cast range skills we store internally range as r^2 to avoid using later Sqr() in distance math sk.range = sk.range * sk.range; sk.manaCost = configServerFile.GetInteger(sec, "mana", 0); sk.minDmg = configServerFile.GetInteger(sec, "minDmg", 0); sk.maxDmg = configServerFile.GetInteger(sec, "maxDmg", 0); sk.race = (int)race; tmp = configServerFile.GetValue(sec, "effectFlag", ""); if (tmp == "") { Output.WriteLine("Corrupted data in skill effect " + sec + ", skipping"); continue; } else { sk.effectFlag = GetSkillEffectFlag(tmp); } tmp = configServerFile.GetValue(sec, "demageFlag", ""); if (tmp == "") { Output.WriteLine("Corrupted data in skill demage " + sec + ", skipping"); continue; } else { sk.demageFlag = GetSkillDemageFlag(tmp); } tmp = configServerFile.GetValue(sec, "magicTypeFlag", ""); if (tmp == "") { Output.WriteLine("Corrupted data in skill magic type " + sec + ", skipping"); continue; } else { sk.magicType = GetSkillMagicTypeFlag(tmp); } sk.aoeRadius = configServerFile.GetInteger(sec, "aoeRadius", 0); sk.maxMultiTargetHits = configServerFile.GetInteger(sec, "maxMultiTargetHits", 0); sk.Request = SkillRequest; sk.Execute = SkillExecute; try { skillList.Add(sk.skillID, sk); Output.WriteLine("Register skill: " + sk.name + " ID: " + sk.skillID); } catch (ArgumentException) { Output.WriteLine("SkillHandler::ReadIniFile " + "Wrong skill ID [" + sk.skillID + "] - " + sk.name + " skipping..."); } } Output.WriteLine(ConsoleColor.DarkCyan, "END register skills"); return(true); }