public override bool FireEvent(Event E)
        {
            if (E.ID == "CommandApplyInjector")
            {
                // Exit if frozen
                if (!ParentObject.CheckFrozen())
                {
                    if (ParentObject.IsPlayer())
                    {
                        Popup.Show("You are frozen!");
                    }
                    return(false);
                }

                // get all injectors, or exit if none
                Body BodyObj = ParentObject.GetPart <Body>();
                List <GameObject> Injectors = BodyObj == null ? null : BodyObj.GetEquippedObjects(InjectorFilter);
                if (Injectors == null || Injectors.Count == 0)
                {
                    if (ParentObject.IsPlayer())
                    {
                        Popup.Show("Equip at least one usable injector in a hand!");
                    }
                    return(false);
                }

                // check if valid target
                Cell Cell = PickDirection();
                if (Cell != null)
                {
                    // Get all valid targets, respecting phasing/flying/light
                    List <GameObject> Targets = Cell.GetObjectsWithPartReadonly("Brain");
                    // Remove hostile targets
                    Targets.RemoveAll(T => T.pBrain.IsHostileTowards(ParentObject));

                    if (Targets.Count == 0)
                    {
                        if (ParentObject.IsPlayer())
                        {
                            Popup.Show("No valid target!");
                        }
                        return(false);
                    }

                    // We have a valid target!  Check if in combat.
                    GameObject Target = Targets[0];
                    foreach (GameObject Injector in Injectors)
                    {
                        if (Target.AreHostilesNearby())                         // Make a attack against DV before injecting
                        {
                            // Lifted from Combat.cs
                            int Roll     = Stat.Random(1, 20);
                            int BaseRoll = Roll;
                            // we don't include movement bonuses in this roll since it's an ability activation
                            Roll += ParentObject.GetIntProperty("HitBonus", 0);

                            if (Injector != null)
                            {
                                Roll += Injector.GetIntProperty("HitBonus", 0);
                            }

                            int AgilityMod = ParentObject.StatMod("Agility");
                            Roll += AgilityMod;
                            Event RollEvent = Event.New("RollMeleeToHit");
                            RollEvent.AddParameter("Weapon", Injector);
                            RollEvent.AddParameter("Damage", 0);
                            RollEvent.AddParameter("Defender", Target);
                            RollEvent.AddParameter("Result", Roll);
                            RollEvent.AddParameter("Skill", "ShortBlades");
                            RollEvent.AddParameter("Stat", "Agility");
                            Injector?.FireEvent(RollEvent);
                            RollEvent.ID = "AttackerRollMeleeToHit";
                            Injector?.FireEvent(RollEvent);
                            Roll = RollEvent.GetIntParameter("Result");
                            Event DVEvent = Event.New("GetDefenderDV");
                            DVEvent.AddParameter("Weapon", Injector);
                            DVEvent.AddParameter("Damage", 0);
                            DVEvent.AddParameter("Defender", Target);
                            DVEvent.AddParameter("NaturalHitResult", BaseRoll);
                            DVEvent.AddParameter("Result", Roll);
                            DVEvent.AddParameter("Skill", "ShortBlades");
                            DVEvent.AddParameter("Stat", "Agility");
                            DVEvent.AddParameter("DV", Stats.GetCombatDV(Target));
                            Target.FireEvent(DVEvent);
                            DVEvent.ID = "WeaponGetDefenderDV";
                            Injector?.FireEvent(DVEvent);
                            // for masterwork mod, plus natural attacker/defender bonuses/penalties
                            int   NaturalHitBonus      = 0;
                            Event NaturalHitBonusEvent = Event.New("GetNaturalHitBonus", "Result", NaturalHitBonus);
                            Injector.FireEvent(NaturalHitBonusEvent);

                            NaturalHitBonusEvent.ID = "AttackerGetNaturalHitBonus";
                            ParentObject.FireEvent(NaturalHitBonusEvent);
                            NaturalHitBonusEvent.ID = "DefenderGetNaturalHitBonus";
                            Target.FireEvent(NaturalHitBonusEvent);
                            NaturalHitBonus = NaturalHitBonusEvent.GetIntParameter("Result");
                            if (BaseRoll + NaturalHitBonus < 20 && Roll <= DVEvent.GetIntParameter("DV"))                             // no autohit
                            {
                                // Chance to fumble, dropping the injector
                                string Color = "&r";

                                int Diff = DVEvent.GetIntParameter("DV") - Roll;
                                if (Stat.Random(1, 20) + AgilityMod <= Diff)
                                {
                                    // fumble!!!
                                    if (ParentObject.IsPlayer())
                                    {
                                        IPart.AddPlayerMessage(Color + "You miss, dropping the " + Injector.DisplayName + "!");
                                    }
                                    ParentObject.FireEvent(Event.New("Unequipped", "UnequippingObject", Injector));
                                    Event UnequipEvent = Event.New("PerformDrop", "Object", Injector);
                                    UnequipEvent.bSilent = E.bSilent;
                                    ParentObject.FireEvent(UnequipEvent);
                                }
                                else
                                {
                                    if (ParentObject.IsPlayer())
                                    {
                                        IPart.AddPlayerMessage(Color + "You miss with the " + Injector.DisplayName + "!");
                                    }
                                }
                                continue;
                            }
                        }

                        IPart.AddPlayerMessage("&gYou apply the " + Injector.DisplayName + " to " + Target.ShortDisplayName + "!");

                        // no hostiles or didn't miss - fire the injector
                        Injector.FireEvent(Event.New("ApplyTonic", "Target", Target, "Attacker", ParentObject));
                        Injector.Destroy((string)null, false, false);
                    }

                    // Deal with energy cost - reduced by short blades skill
                    int EnergyCost = 1000;
                    if (ParentObject.HasSkill("ShortBlades_Expertise"))
                    {
                        EnergyCost = 750;
                    }
                    ParentObject.UseEnergy(EnergyCost, "Physical Skill");
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 2
0
 public override bool FireEvent(Event E)
 {
     if (E.ID == "BeginTakeAction")
     {
         CheckConstricted();
         if (Constricted != null && !ParentObject.pBrain.HasGoal("FleeLocation"))
         {
             ParentObject.pBrain.Goals.Clear();
         }
     }
     else if (E.ID == "ObjectEnteredAdjacentCell")
     {
         GameObject gameObjectParameter = E.GetGameObjectParameter("Object");
         if (gameObjectParameter != null && ParentObject.pBrain.IsHostileTowards(gameObjectParameter))
         {
             CheckConstricted();
             if (Constricted == null && !gameObjectParameter.MakeSave("Strength", 20, null, null, "Constrictment"))
             {
                 Constrict(gameObjectParameter, null);
             }
         }
     }
     else if (E.ID == "EnteredCell")
     {
         if (Constricted != null)
         {
             if (ParentObject.CurrentCell != null)
             {
                 if (Constricted.CurrentCell != null && Constricted.CurrentCell != ParentObject.CurrentCell)
                 {
                     Constricted.CurrentCell.RemoveObject(Constricted);
                 }
                 if (!ParentObject.CurrentCell.Objects.Contains(Constricted))
                 {
                     ParentObject.CurrentCell.AddObject(Constricted);
                 }
             }
             Constricted.FireEvent(Event.New("ConstrictDragged", "Object", ParentObject));
             ParentObject.FireEvent(Event.New("ConstricterDragged", "Object", Constricted));
         }
         CheckConstricted();
     }
     else if (E.ID == "BeginBeingTaken")
     {
         EndAllConstriction();
     }
     else if (E.ID == "AIGetOffensiveMutationList")
     {
         CheckConstricted();
         if (Constricted == null)
         {
             int intParameter = E.GetIntParameter("Distance");
             ActivatedAbilityEntry ActivatedAbility = MyActivatedAbility(ActivatedAbilitiesID);
             if (ActivatedAbility != null && ActivatedAbility.Cooldown <= 0 && intParameter <= 1)
             {
                 GameObject gameObjectParameter2 = E.GetGameObjectParameter("Target");
                 if (gameObjectParameter2.PhaseAndFlightMatches(ParentObject))
                 {
                     List <AICommandList> list = E.GetParameter("List") as List <AICommandList>;
                     list.Add(new AICommandList("CommandConstrict", 1));
                 }
             }
         }
     }
     // Allows both player and AI to direction a cell to activate the mutation on
     else if (E.ID == "CommandConstrict")
     {
         // AddPlayerMessage("Phase: check frozen");
         if (!ParentObject.CheckFrozen())
         {
             return(true);
         }
         CheckConstricted();
         Cell cell = base.PickDirection(null);
         // AddPlayerMessage("Phase: CooldownSet");
         if (cell != null)
         {
             CooldownMyActivatedAbility(ActivatedAbilitiesID, 15);
         }
         {
             GameObject combatTarget = cell.GetCombatTarget(ParentObject, false, false, false, null, true, true, false, null);
             // AddPlayerMessage("Phase: Combat target grabbed");
             if (combatTarget != null && combatTarget != ParentObject)
             {
                 if (Constricted != null)
                 {
                     // AddPlayerMessage("Phase: end constrict");
                     EndConstriction(Constricted, null, null);
                 }
                 // AddPlayerMessage("Phase: start constrict");
                 Constrict(combatTarget, null);
             }
         }
     }
     return(base.FireEvent(E));
 }