public static bool PsionicsCanBeUsed(Ship ship, CombatAI cmdAI) { if (ship == null || ship.CurrentPsiPower <= 0 || ship.Psionics.Count <Psionic>() == 0) { return(false); } bool flag = false; foreach (Psionic psionic in ship.Psionics) { if (ShipPsionicControl.CanUsePsionic(ship, psionic, cmdAI)) { flag = true; break; } } return(flag); }
private void Think(int framesElapsed) { if (this.m_Ship.Target == null || !ShipPsionicControl.PsionicsCanBeUsed(this.m_Ship, this.m_CommanderAI)) { this.m_CurrUpdateFrame = this.m_CurrMaxUpdateFrame; } else if (this.m_Ship.Target is Ship && !Ship.IsActiveShip(this.m_Ship.Target as Ship) || this.m_Ship.Target is StellarBody && (this.m_Ship.Target as StellarBody).Population <= 0.0) { this.m_CurrUpdateFrame = this.m_CurrMaxUpdateFrame; } else { this.m_CurrUpdateFrame -= framesElapsed; if (this.m_CurrUpdateFrame > 0) { return; } this.m_CurrMaxUpdateFrame = this.m_CommanderAI.AIRandom.NextInclusive(this.m_MinFrames, this.m_MaxFrames); this.m_CurrUpdateFrame = this.m_CurrMaxUpdateFrame; this.m_State = PsionicControlState.ChoosePsionic; } }
private void ChoosePsionic() { if (this.m_Ship == null || this.m_Ship.Target == null) { return; } this.m_HoldPsionic = (Psionic)null; Psionic psionic1 = (Psionic)null; float maxValue = 0.0f; Dictionary <Psionic, float> dictionary = new Dictionary <Psionic, float>(); foreach (Psionic psionic2 in this.m_Ship.Psionics) { float weightForPsionic = ShipPsionicControl.GetWeightForPsionic(this.m_CommanderAI, this.m_Ship, psionic2); if ((double)weightForPsionic > 0.0) { dictionary.Add(psionic2, weightForPsionic); maxValue += weightForPsionic; } } if (dictionary.Count == 0) { this.m_State = PsionicControlState.Think; } else { float num = this.m_CommanderAI.AIRandom.NextInclusive(1f, maxValue); foreach (KeyValuePair <Psionic, float> keyValuePair in dictionary) { if ((double)num <= (double)keyValuePair.Value) { psionic1 = keyValuePair.Key; break; } num -= keyValuePair.Value; } if (psionic1 == null) { return; } psionic1.Activate(); if (ShipPsionicControl.IsHoldPsionic(psionic1)) { this.m_State = PsionicControlState.HoldPsionic; this.m_HoldPsionic = psionic1; } else { switch (psionic1.Type) { case SectionEnumerations.PsionicAbility.Repair: case SectionEnumerations.PsionicAbility.Inspiration: case SectionEnumerations.PsionicAbility.Block: psionic1.PostSetProp("SetTarget", (IGameObject)this.m_CommanderAI.GetFriendlyShips()[this.m_CommanderAI.AIRandom.Next(this.m_CommanderAI.GetFriendlyShips().Count)]); break; default: psionic1.PostSetProp("SetTarget", this.m_Ship.Target.ObjectID); break; } psionic1.Deactivate(); this.m_State = PsionicControlState.Think; } } }