Ejemplo n.º 1
0
        internal FollowController(AI_StateMachine ai)
        {
            this.pathToFollow = new Queue <Vector2>();
            this.ai           = ai;
            this.leader       = ai.farmer;
            this.follower     = ai.npc;
            this.pathFinder   = new PathFinder(this.follower.currentLocation, this.follower, this.leader);
            this.joystick     = new NpcMovementController(this.follower, this.pathFinder);

            this.ai.LocationChanged += this.Ai_LocationChanged;
            this.joystick.Move      += this.OnMove;
        }
Ejemplo n.º 2
0
        public ForageController(AI_StateMachine ai, IModEvents events)
        {
            this.ai         = ai;
            this.ignoreList = new List <TerrainFeature>();
            this.pathFinder = new PathFinder(this.Forager.currentLocation, this.Forager, this.ai.player);
            this.joystick   = new NpcMovementController(this.Forager, this.pathFinder);
            this.joystick.EndOfRouteReached += this.Joystick_EndOfRouteReached;
            this.ai.LocationChanged         += this.Ai_LocationChanged;
            this.r = new Random((int)Game1.uniqueIDForThisGame + (int)Game1.stats.DaysPlayed);
            this.foragedObjects = new Stack <Item>();
            this.forages        = this.LoadForages();

            events.GameLoop.TimeChanged += this.GameLoop_TimeChanged;
        }
Ejemplo n.º 3
0
    public static NpcObject Instantiate(List <Tuple <int, int> > personalityValues, string modelName)
    {
        if (modelName.Equals("random"))
        {
            var randomIndexForModelName = Random.Range(0, SettingsParser.ModelNames.Count);
            modelName = SettingsParser.ModelNames[randomIndexForModelName];
        }
        var randomIndexForPosition = Random.Range(0, SettingsParser.Spawnpoints.Count);
        var randomPosition         = SettingsParser.Spawnpoints[randomIndexForPosition];

        var npcObject = (Instantiate(
                             Resources.Load(modelName),
                             randomPosition,
                             Quaternion.identity)
                         as GameObject).GetComponent <NpcObject>();

        npcObject.Id = AllPersons.Count;
        npcObject.PersonalityValuesGenericVector = personalityValues.SetUpGenericVector();
        npcObject.AccumulatedValues      = new GenericVector(personalityValues.Count);
        npcObject.CurrentNodesCollection = ActionsParser.NormalActions;
        npcObject.GraphTraveler          = new GraphTraveler(npcObject);
        npcObject.MovementController     = NpcMovementController.CreateComponent(npcObject.gameObject, npcObject);
        npcObject.Animator = npcObject.gameObject.GetComponent <Animator>();
        npcObject.gameObject.AddComponent <UnityEngine.AI.NavMeshAgent>();
        npcObject.gameObject.AddComponent <AudioSource>();
        npcObject.gameObject.GetComponent <UnityEngine.AI.NavMeshAgent>().stoppingDistance = 2.2f;
        npcObject.gameObject.GetComponent <UnityEngine.AI.NavMeshAgent>().speed            = 2.0f;
        npcObject.gameObject.GetComponent <UnityEngine.AI.NavMeshAgent>().angularSpeed     = 12.0f;


        npcObject.gameObject.AddComponent <AudioSource>();
        var audio = npcObject.gameObject.GetComponent <AudioSource>();

        audio.clip         = Resources.Load <AudioClip>("Footstep01");
        audio.playOnAwake  = false;
        audio.loop         = true;
        audio.rolloffMode  = AudioRolloffMode.Linear;
        audio.maxDistance  = 5.0f;
        audio.minDistance  = 0.0f;
        audio.spatialBlend = 1.0f;
        AllPersons.Add(npcObject);

        return(npcObject);
    }
Ejemplo n.º 4
0
        public FishController(AI_StateMachine ai, IModEvents events)
        {
            this.ai          = ai;
            this.fisher      = ai.npc;
            this.farmer      = ai.farmer;
            this.fishingSpot = this.negativeOne;
            this.pathFinder  = new PathFinder(this.fisher.currentLocation, this.fisher, this.farmer);
            this.joystick    = new NpcMovementController(this.fisher, this.pathFinder);
            this.fishCaught  = new Stack <SObject>();

            if (!ai.Csm.HasSkill("fisherman"))
            {
                return;
            }

            ai.LocationChanged              += this.Ai_LocationChanged;
            events.GameLoop.TimeChanged     += this.OnTimeChanged;
            this.joystick.EndOfRouteReached += this.ArrivedFishingSpot;

            string key = $"{ai.npc.Name.ToLower()}_sideFish";
            var    animationDescriptions = this.ai.ContentLoader.LoadData <string, string>("Data/AnimationDescriptions");

            if (!animationDescriptions.ContainsKey(key))
            {
                ai.Monitor.Log($"No fishing animation for `{ai.npc.Name}`: Key `{key}` doesn't exist.", LogLevel.Error);
                return;
            }

            string[] animation = animationDescriptions[key].Split('/');

            if (animation.Length < 3)
            {
                ai.Monitor.Log($"Wrong animation description format for key `{key}`", LogLevel.Error);
                return;
            }

            int[] frames = Utility.parseStringToIntArray(animation[1]);

            this.fishingLeftAnim  = frames.Select(f => new FarmerSprite.AnimationFrame(f, 4000, false, true, null, false)).ToList();
            this.fishingRightAnim = frames.Select(f => new FarmerSprite.AnimationFrame(f, 4000)).ToList();
        }