public static void StopSpecificTask_Postfix(HumanAI __instance, Interactable interactable)
 {
     if (interactable != null && interactable.interactionLockID < 0 && interactable.interactionLockID == Math.Abs(__instance.GetID()))
     {
         interactable.SetInteractionLockID(0);
     }
 }
Example #2
0
 public override IEnumerable <InteractionRestricted> GetInteractionRestricted(HumanAI human)
 {
     yield return(new InteractionRestricted(Interaction.Produce, new InteractionRestrictionProduction(new List <string>()
     {
         "beer"
     })));
 }
Example #3
0
    void Awake()
    {
        ai = GetComponentInParent <HumanAI>();
        int lookIndex = Random.Range(0, 2);

        HumanSprite = RandomizedLooks[lookIndex];
    }
Example #4
0
    private void HitHumanAI(HumanAI human, Vector3 hit_pos, Vector3 hit_dir)
    {
        if (!human.CanReceiveHit())
        {
            return;
        }
        this.m_AudioModule.PlayHitSound(1f, false);
        Item   currentItem = this.m_Player.GetCurrentItem(Hand.Right);
        Weapon weapon      = null;

        if (currentItem.m_Info.IsWeapon())
        {
            weapon = (Weapon)currentItem;
        }
        if (!human.IsDead())
        {
            this.ExecuteSkill(currentItem);
        }
        DamageInfo damageInfo = new DamageInfo();

        damageInfo.m_Damage     = ((!(weapon != null)) ? 1000f : ((WeaponInfo)weapon.m_Info).m_HumanDamage);
        damageInfo.m_Damage    *= this.GetDamageMultiplier(currentItem);
        damageInfo.m_DamageItem = currentItem;
        damageInfo.m_Damager    = this.m_Player.gameObject;
        damageInfo.m_Position   = hit_pos;
        damageInfo.m_HitDir     = hit_dir;
        damageInfo.m_Normal     = -hit_dir;
        human.TakeDamage(damageInfo);
    }
Example #5
0
        public override IEnumerable <InteractionRestricted> GetInteractionRestricted(HumanAI human)
        {
            List <String> orderedMeds = new List <string>();

            foreach (var sub in this.GetOrderedSubSpecializations())
            {
                switch (sub.Name)
                {
                case "Doctor_ProduceMedicine_FluVaccines": orderedMeds.Add("medicine"); break;

                case "Doctor_ProduceMedicine_HealingPotions": orderedMeds.Add("healingPotion"); break;
                }
            }

            if (this.AutoManageSubSpecializations)
            {
                orderedMeds.Sort((x, y) => GetResourceRatio(GameState.GetResourceByString(x)).CompareTo(GetResourceRatio(GameState.GetResourceByString(y))));
            }

            foreach (var med in orderedMeds)
            {
                var intRes = new InteractionRestricted(Interaction.Produce, new InteractionRestrictionProduction(new List <string>()
                {
                    med
                }));
                yield return(intRes);
            }
        }
Example #6
0
    void OnTriggerEnter(Collider other)
    {
        HumanAI human = other.GetComponent <HumanAI>();

        if (human != null)
        {
            Debug.Log(other.name + " arrived at " + name + "!");
            human.OnEnterRoom(this);
            Humans.Add(human);
        }
        else
        {
            RoomSampler roomSampler = other.GetComponent <RoomSampler>();
            if (roomSampler != null)
            {
                Door door = roomSampler.GetComponentInParent <Door>();
                door.Rooms.Add(this);
                if (!Doors.Contains(door))
                {
                    Doors.Add(door);
                }
            }
            else
            {
                PossessableProp prop = other.GetComponent <PossessableProp>();
                if (prop != null)
                {
                    prop.GetComponentInParent <PossessableProp>().currentRoom = this;
                }
            }
        }
    }
        public static bool ShowPrefix(BirthdayChildPanel __instance, HumanAI child)
        {
            Transform panel = __instance.transform.GetChild(0);

            if (panel.Find("ButtonContainer") == null)
            {
                PlannedParenthoodMod.SetupBirthdayPanel(__instance);
            }

            __instance.descriptionText.text = String.Format(Localization.GetText("witchy_PlannedParenthood_BirthdayPanelText"), child.father.GetFullName(), child.mother.GetFullName());

            String randomGirlName = HumanManager.GetRandomHumanNamePart(false, Gender.Female);
            String randomBoyName  = HumanManager.GetRandomHumanNamePart(false, Gender.Male);
            String lastName       = (UnityEngine.Random.Range(0f, 1f) < 0.5f) ? child.mother.lastName : child.father.lastName;

            panel.Find("GirlPanel").GetComponentInChildren <InputField>().text = $"{randomGirlName} {lastName}";
            panel.Find("BoyPanel").GetComponentInChildren <InputField>().text  = $"{randomBoyName} {lastName}";

            PlannedParenthoodMod.InputChanged(__instance);

            AccessTools.Field(typeof(BirthdayChildPanel), "child").SetValue(__instance, child);

            __instance.gameObject.SetActive(true);

            return(false);
        }
Example #8
0
        public override IEnumerable <InteractionRestricted> GetInteractionRestricted(HumanAI human)
        {
            List <string> list = new List <string>();

            foreach (var sub in this.GetOrderedSubSpecializations().Select(x => x.Name))
            {
                switch (sub)
                {
                case "Scholar_PerformResearch_BookStand": list.Add("analyzeCrystal"); break;

                case "Scholar_PerformResearch_ScrollStand": list.Add("analyzeScroll"); break;
                }
            }

            if (this.AutoManageSubSpecializations)
            {
                yield return(new InteractionRestricted(Interaction.Produce, new InteractionRestrictionNameKey(list.ToArray())));
            }
            else
            {
                foreach (var filter in list)
                {
                    yield return(new InteractionRestricted(Interaction.Produce, new InteractionRestrictionNameKey(filter)));
                }
            }
        }
        public static void AcceptClicked(BirthdayChildPanel bdPanel)
        {
            bdPanel.gameObject.SetActive(false);

            HumanAI oldChild = (HumanAI)AccessTools.Field(typeof(BirthdayChildPanel), "child").GetValue(bdPanel);

            HumanConfiguration config = new HumanConfiguration(oldChild.humanType, AgeLevel.Child, 0f, oldChild.mother, oldChild.father);

            Relationship relationship = WorldScripts.Instance.relationshipManager.GetRelationship(oldChild.father, oldChild.mother);

            HumanAI newChild = WorldScripts.Instance.humanManager.SpawnHuman(config, relationship.GetFirstHuman().GetPosition(), relationship.GetFirstHuman().faction, true, null);

            newChild.mother.onHadChild.Invoke(newChild);
            newChild.father.onHadChild.Invoke(newChild);

            relationship.HadChild();

            WorldScripts.Instance.relationshipManager.SetRelationship(RelationshipLevel.Friend, 0.8f, newChild, newChild.mother);
            WorldScripts.Instance.relationshipManager.SetRelationship(RelationshipLevel.Friend, 0.8f, newChild, newChild.father);

            String childName = bdPanel.transform.GetChild(0).Find((newChild.gender == Gender.Female ? "GirlPanel" : "BoyPanel")).GetComponentInChildren <InputField>().text;

            newChild.SetName(childName);

            WorldScripts.Instance.cameraMovement.PanToPosition(newChild.GetPosition());

            PlannedParenthoodMod.InAddChild = false;
        }
        public override IEnumerable <InteractionRestricted> GetInteractionRestricted(HumanAI human)
        {
            yield return(new InteractionRestricted(Interaction.Construct,
                                                   new InteractionRestrictionConstructableType(ConstructableType.Fields)));

            yield return(new InteractionRestricted(Interaction.Deconstruct, 50));
        }
        public static bool GoToAFunActivity(this HumanAI humanAI, uint citizenId, ref Citizen citizen, ushort proximityBuilding, float distance)
        {
            var visitMonument             = SimulationManager.instance.m_randomizer.Int32(10) < (humanAI is TouristAI ? 6 : 2);
            var proximityBuildingInstance = BuildingManager.instance.m_buildings.m_buffer[proximityBuilding];

            if (visitMonument && proximityBuilding != 0)
            {
                var monument = humanAI.FindSomewhere(citizenId, ref citizen, proximityBuildingInstance, new[] { ItemClass.Service.Monument }, new[] { ItemClass.SubService.None }, distance * 5);
                if (monument != 0)
                {
                    humanAI.GoToBuilding(citizenId, ref citizen, monument);

                    return(true);
                }
            }

            var foundBuilding = humanAI.FindSomewhere(citizenId, ref citizen, proximityBuildingInstance, new[] { ItemClass.Service.Beautification, ItemClass.Service.Commercial, ItemClass.Service.Natural, ItemClass.Service.Tourism }, new[] { ItemClass.SubService.None }, distance);

            if (foundBuilding != 0)
            {
                humanAI.GoToBuilding(citizenId, ref citizen, foundBuilding);

                return(true);
            }

            return(false);
        }
 public override IEnumerable <InteractionRestricted> GetInteractionRestricted(HumanAI human)
 {
     yield return(new InteractionRestricted(Interaction.GatherResource, new List <InteractionRestriction>()
     {
         new InteractionRestrictionResource(Resource.Apple),
         new InteractionRestrictionDesignation(Designation.GatherPlant)
     }));
 }
Example #13
0
    void OnGUI()
    {
        GUILayout.Label("Adjust AI", EditorStyles.boldLabel);
        human = EditorGUILayout.ObjectField("Target AI (GameObject):", human, typeof(GameObject), false) as GameObject;

        GUILayout.Space(5f);

        name = EditorGUILayout.TextField("Name:", name);

        GUILayout.Space(10f);

        speed          = EditorGUILayout.Slider("Speed", speed, 0, 20);
        wanderDuration = EditorGUILayout.Slider("Wander Duration", wanderDuration, 50, 500);
        turnSpeed      = EditorGUILayout.Slider("Turn speed", turnSpeed, 0, 20);

        GUILayout.Space(10f);

        groupEnabled      = EditorGUILayout.BeginToggleGroup("Imperfection?", groupEnabled);
        proneToDepression = EditorGUILayout.Toggle("Prone to depression", proneToDepression);
        Gluttenous        = EditorGUILayout.Toggle("Gluttenous", Gluttenous);
        unfaithful        = EditorGUILayout.Toggle("Unfaithful", unfaithful);
        EditorGUILayout.EndToggleGroup();

        GUILayout.Space(10f);

        if (GUILayout.Button("Instantiate AI"))
        {
            if (speed == 0 || turnSpeed == 0)
            {
                Debug.LogWarning("Some AI values are set to zero!");
            }
            if (name == null)
            {
                Debug.LogWarning("This unit's name has not been set!");
            }

            GameObject ai      = Instantiate(human, Vector3.zero, Quaternion.identity);
            HumanAI    humanAI = ai.GetComponent <HumanAI>();

            humanAI.name           = name;
            humanAI.speed          = speed;
            humanAI.wanderDuration = wanderDuration;
            humanAI.turnSpeed      = turnSpeed;

            if (proneToDepression)
            {
                // (Increase chance to get depression, yet to be implemented.)
                if (Gluttenous)
                {
                    // (Make the human count twice as much for the food calculation, yet to be implemented.)
                    if (unfaithful)
                    {
                        humanAI.IncreaseFaithOverTime(true);
                    }
                }
            }
        }
    }
 private void InitColonistForSubSpecialization(HumanAI human, string subSpecName,
                                               SubSpecializationDescriptor desc, Specialization spec)
 {
     if (!spec.SubSpecializations.ContainsKey(subSpecName))
     {
         spec.SubSpecializations.Add(subSpecName,
                                     desc.ToSubSpecialization(spec.SubSpecializations.Count));
     }
 }
        public void SetHuman(HumanAI human)
        {
            this.Human = human;

            if (this.ToolTip != null)
            {
                UpdateInteraction(this.Human.GetCurrentInteractionInfo());
            }
        }
Example #16
0
 public override IEnumerable <InteractionRestricted> GetInteractionRestricted(HumanAI human)
 {
     yield return(new InteractionRestricted(Interaction.Produce,
                                            new List <InteractionRestriction>()
     {
         new InteractionRestrictionProfessionSpecialization(this.Name),
         new InteractionRestrictionProfession(ProfessionType.Craftsman)
     }));
 }
 public static void Postfix(NeedsInteractionController __instance, HumanAI human, ref InteractionInfo __result)
 {
     if (__result != null && (
             (__result.interaction == Interaction.Sleep && human.energy >= 0.15f) ||
             (__result.interaction == Interaction.SleepOnGround && human.energy > 0)))
     {
         __result = null;
     }
 }
Example #18
0
        public static void Postfix(PortraitPanel __instance, HumanAI human)
        {
            GameObject             namePanelWrapper = __instance.background.transform.Find("namePanelWrapper").gameObject;
            SatisfactionPointsText spText           = namePanelWrapper.transform.Find("Panel").GetComponentInChildren <SatisfactionPointsText>(true);
            PortraitCurrentTask    ct = __instance.background.GetComponentInChildren <PortraitCurrentTask>();;

            spText.SetHuman(human);
            ct.SetHuman(human);
        }
Example #19
0
 public void AssignActor(Actor actor, string headNodePath, string torsoPath)
 {
     this.actor = actor;
     jumpThrust = new Vector3();
     head       = FindNode(headNodePath) as Spatial;
     torso      = FindNode(torsoPath) as CollisionShape;
     agent      = new HumanAI(this);
     Resume();
 }
Example #20
0
    //Window -> Package Manager -> Burst
    //[BurstCompile(CompileSynchronously = true)]
    IEnumerator Wave(float force, int wave)
    {
        float radius;

        if (wave == 0)
        {
            radius = highDangerZone;
        }
        else if (wave == 1)
        {
            force  = force / 2;
            radius = lowDangerZone;
        }

        else if (wave == 2)
        {
            force  = force / 2;
            radius = shockwave;
        }

        else
        {
            yield break;
        }

        Collider[] colliders = Physics.OverlapSphere(transform.position, radius);
        foreach (Collider hit in colliders)
        {
            Rigidbody rb = hit.GetComponent <Rigidbody>();
            if (rb != null)
            {
                if (rb.transform.root.gameObject.layer == 14)
                {
                    HumanAI human = rb.transform.root.GetComponent <HumanAI>();
                    if (human)
                    {
                        if (!human.getHit)
                        {
                            //use ecs system
                            //raycast wall control
                            human.Hit((transform.position - rb.transform.position).magnitude);
                            rb.AddExplosionForce(force, transform.position, radius, 3.0F);
                        }
                    }
                }
                else
                {
                    //hit environment use animations not rigidbodies !!!
                }
            }
        }
        yield return(new WaitForFixedUpdate());

        wave++;
        StartCoroutine(Wave(explosionForce, wave));
    }
        public static void Postfix(IdleInteractionController __instance, ref Interaction __result)
        {
            FieldInfo fInfo = typeof(IdleInteractionController).GetField("human", BindingFlags.NonPublic | BindingFlags.Instance);
            HumanAI   human = (HumanAI)fInfo.GetValue(__instance);

            if ((human.IsLazy() || human.uncontrollableReasons.Count > 0) && !_AllowedInteractions.Contains(__result))
            {
                __result = _AllowedInteractions[new Random().Next(0, _AllowedInteractions.Length)];
            }
        }
 public static void GetInteractionsPrefix(Profession __instance, HumanAI human, List <InteractionRestricted> list)
 {
     //If the colonist has the specialization "Build" enabled, adds Construct and Deconstruct
     //to the list of available interactions
     if (__instance.HasSpecialization("build"))
     {
         list.Add(new InteractionRestricted(Interaction.Construct, __instance.priority * 20));
         list.Add(new InteractionRestricted(Interaction.Deconstruct, __instance.priority * 20));
     }
 }
Example #23
0
    void OnTriggerExit(Collider other)
    {
        HumanAI human = other.GetComponent <HumanAI>();

        if (human != null)
        {
            Debug.Log(other.name + " exited from " + name + "!");
            Humans.Remove(human);
        }
    }
        public static ushort FindSomewhere(this HumanAI humanAI, uint citizenId, ref Citizen citizen, Building building, ItemClass.Service[] services, ItemClass.SubService[] subServices, float distance)
        {
            var buildingInstance = citizen.GetBuildingInstance();

            if (buildingInstance.HasValue)
            {
                return(humanAI.FindSomewhere(citizenId, ref citizen, buildingInstance.Value.m_position, services, subServices, distance));
            }

            return(0);
        }
Example #25
0
 private void Fire(HumanAI ai)
 {
     this.m_Animation.CrossFade(this.m_FireAnimName);
     this.SetArmed(false);
     if (ai)
     {
         ai.GiveDamage(base.gameObject, this, 9999f, -base.transform.forward, DamageType.None, 0, false);
         this.m_Body = ai.gameObject.GetComponent <DeadBody>();
         this.m_Joint.connectedBody = ai.m_KillerTrapJoint;
     }
 }
        public Specialization GetForesterSpecialization(HumanAI human, int priority, bool active, SubSpecialization[] subs)
        {
            switch (this.Name)
            {
            case "chopTrees": return(new ChopTreesSpecialization(priority, active, subs));

            case "growTrees": return(new GrowTreesSpecialization(priority, active, subs));

            default: return(null);
            }
        }
        public Specialization GetScholarSpecialization(HumanAI human, int priority, bool active, SubSpecialization[] subs)
        {
            switch (this.Name)
            {
            case "performResearch": return(new PerformResearchSpecialization(priority, active, subs));

            case "mineCrystal": return(new MineCrystalSpecialization(this.Profession, priority, active, subs));

            default: return(null);
            }
        }
Example #28
0
        public static bool HigherPriorityLoop_Prefix(ProfessionDetailPanel __instance)
        {
            HumanAI        human = __instance.GetFieldValue <HumanAI>("human");
            ProfessionType type  = __instance.GetPropertyValue <ProfessionType>("type");

            int prio = human.professionManager.GetProfession(type).priority + 1;

            human.professionManager.SetPriority(type, prio, human);
            __instance.InvokeMethod("UpdatePriority");

            return(false);
        }
        public override IEnumerable <InteractionRestricted> GetInteractionRestricted(HumanAI human)
        {
            var restrictions = new List <InteractionRestriction>()
            {
                new InteractionRestrictionFaction()
            };

            foreach (var interaction in new Interaction[] { Interaction.TryFluTreatment, Interaction.GiveFood, Interaction.GiveHealingPotion, Interaction.BandageWounds, Interaction.SplintArm, Interaction.SplintLeg })
            {
                yield return(new InteractionRestricted(interaction, restrictions, 50));
            }
        }
        public static void SetHumanPostFix(ProfessionDetailPanel __instance, HumanAI human)
        {
            //Get our new panel
            SpecializationPanel p = __instance.GetComponentInChildren <SpecializationPanel>(true);

            //If it exists (depends on the stage of the lifecycle of the UI)
            //If it does, call SetHuman on our panel
            if (p != null)
            {
                p.SetHuman(human);
            }
        }