Пример #1
0
    public static void UpdateAI(this IArtificialIntelligence ai)
    {
        if (ai.Server == null || !((Character)ai.GetSceneChar()).IsAlive)
        {
            return;
        }

        if (ai.Target == null)
        {
            ai.Target = ai.GetSceneChar().FindNearestEnemy(ai.Server.SceneCharacters.Values);
        }

        //Debug.Log( "AI Target is " + Target + " at " + Target.transform.position );

        // If there was no nearest enemy found, then don't do anything
        if (ai.Target == null)
        {
            return;
        }

        if (((Character)ai.Target).IsAlive)
        {
            ai.RunAtTarget();
            ai.AttackTarget();
        }
    }
Пример #2
0
    /// <summary>
    /// Instantiates an AI to attack players
    /// </summary>
    private void InstantiateAI()
    {
        Debug.Log("instantiating AI");
        Debug.Log("spawn point is " + SceneInformation.AiSpawn);

        var aiInstantiation = (GameObject)GameObject.Instantiate(
            AIPrefab,
            SceneInformation.AiSpawn.position,
            SceneInformation.AiSpawn.rotation);

        Debug.Log("AI Instantiation: " + aiInstantiation);

        IArtificialIntelligence aiSceneCharacter = null;

        aiSceneCharacter = aiInstantiation.GetComponent <AI3D>();


        if (aiSceneCharacter == null)
        {
            throw new InvalidOperationException("AI prefab needs an AI component that matches the 3D/2D aspect of the game");
        }

        ////Debug.Log ("AI scene char: " + aiSceneCharacter);

        int charId = AI_ID_INDEX + AICount;

        AICount++;

        aiSceneCharacter.Server = this;
        ((Character)aiSceneCharacter.GetSceneChar()).Team = "AI";
        ((Character)aiSceneCharacter.GetSceneChar()).Id   = charId;

        Debug.Log("Adding AI character " + aiSceneCharacter.BaseCharacter.CharName + " with ID " + charId);

        SceneCharacters.Add(charId, aiSceneCharacter.GetSceneChar());
        foreach (var charId2 in SceneCharacters.Keys)
        {
            Debug.Log("Scene characters contains key: " + charId2);
        }

        GetComponent <NetworkView>().RPC("InitNewSceneCharacter", RPCMode.Others, aiSceneCharacter.BaseCharacter.Serialize());
    }