public bool Event_OnAttack(ComponentEvent e) { var baseAttack = (EOnPerformAttack)e; // if there was a skill waiting to be used as an attack modifier, pass along this attack event to be modified if (pendingAttackSkill != null) { float attributeModifier = CombatEngine.GetEntitySkillStrength(owner, pendingAttackSkill); // add the fact that it was a skill being used to the original combat baseAttack.damageEvent.combat.Set("skill", pendingAttackSkill); ECompileSkillEffects compileSkillEvent = new ECompileSkillEffects() { user = owner, skillStrength = attributeModifier, baseLocation = baseAttack.damageEvent.combat.defender.position, }; compileSkillEvent.combats.Add(baseAttack.damageEvent.combat); pendingAttackSkill.FireEvent(compileSkillEvent); foreach (var combat in compileSkillEvent.combats) { CombatEngine.ProcessCombat(combat); } // check if the skill is done var skillCompleted = (EGetSkillCompleted)pendingAttackSkill.FireEvent(new EGetSkillCompleted() { isCompleted = true }); // and reset the skill if (skillCompleted.isCompleted) { pendingAttackSkill = null; } // set the base attack state to not apply damage, because the skill handles it baseAttack.canPerform = false; } return(true); }
/// <summary> /// When a skill recieves an activation event, it will come back here, where it can be handled by the correct system. /// This is done because some skills use targeting UI / AI and some use attack events and some are immediate /// </summary> public bool Event_HandleSkillActivation(ComponentEvent e) { var activationEvent = (EOnSkillActivated)e; Entity skill = activationEvent.skill; // check how much energy the skill uses, and dont let it be used if its too much var checkSkillReq = (EGetEnergy)skill.FireEvent(new EGetEnergy()); if (checkSkillReq.requiredEnergy > currentEnergy) { return(true); } bool skillActivated = false; // Handle different use mode cases. switch (activationEvent.useMode) { case SkillUseMode.EType.NextAttack: // for now, only one pending attack skill can be active at a time if (pendingAttackSkill == null) { pendingAttackSkill = skill; skillActivated = true; } else if (pendingAttackSkill == skill) { // if the same skill is re-activated, cancel it pendingAttackSkill = null; } break; case SkillUseMode.EType.Targeted: // TODO: delegate this somehow to UI or AI to select the target location / entity break; case SkillUseMode.EType.Self: // use immediatly on self skillActivated = true; float attributeModifier = CombatEngine.GetEntitySkillStrength(owner, skill); var skillEffects = new ECompileSkillEffects() { user = owner, skillStrength = attributeModifier, baseLocation = owner.position, }; skillEffects.combats.Add(new CombatInstance(owner, owner) { { "skill", skill } }); skill.FireEvent(skillEffects); // process the events foreach (var combat in skillEffects.combats) { CombatEngine.ProcessCombat(combat); } break; } // if the skill was activated, reduce the energy level if (skillActivated) { currentEnergy -= checkSkillReq.requiredEnergy; nextEnergyPoint = 0; } return(true); }