示例#1
0
        public void UpdateCharmAI()
        {
            if (IsCharmed())
            {
                UnitAI newAI = null;
                if (IsPlayer())
                {
                    Unit charmer = GetCharmer();
                    if (charmer != null)
                    {
                        // first, we check if the creature's own AI specifies an override playerai for its owned players
                        Creature creatureCharmer = charmer.ToCreature();
                        if (creatureCharmer != null)
                        {
                            CreatureAI charmerAI = creatureCharmer.GetAI();
                            if (charmerAI != null)
                            {
                                newAI = charmerAI.GetAIForCharmedPlayer(ToPlayer());
                            }
                        }
                        else
                        {
                            Log.outError(LogFilter.Misc, $"Attempt to assign charm AI to player {GetGUID()} who is charmed by non-creature {GetCharmerGUID()}.");
                        }
                    }
                    if (newAI == null) // otherwise, we default to the generic one
                    {
                        newAI = new SimpleCharmedPlayerAI(ToPlayer());
                    }
                }
                else
                {
                    Cypher.Assert(IsCreature());
                    if (IsPossessed() || IsVehicle())
                    {
                        newAI = new PossessedAI(ToCreature());
                    }
                    else
                    {
                        newAI = new PetAI(ToCreature());
                    }
                }

                Cypher.Assert(newAI != null);
                SetAI(newAI);
                newAI.OnCharmed(true);
            }
            else
            {
                RestoreDisabledAI();
                // Hack: this is required because we want to call OnCharmed(true) on the restored AI
                RefreshAI();
                UnitAI ai = GetAI();
                if (ai != null)
                {
                    ai.OnCharmed(true);
                }
            }
        }