Esempio n. 1
0
    public static void SetupEvents(Equippable equip)
    {
        ItemPickup pickup   = equip.GetComponent <ItemPickup>();
        Collider   collider = equip.GetComponent <Collider>();

        bool pickupHides   = !pickup || !pickup.worldView;
        bool colliderHides = !(collider != null);
        bool skinShows     = !equip.equip;

        if (equip.equipped != null)
        {
            for (int i = 0; i < equip.equipped.GetPersistentEventCount(); i++)
            {
                string method       = equip.equipped.GetPersistentMethodName(i);
                var    targetObject = equip.equipped.GetPersistentTarget(i);

                if (!colliderHides && (method == "set_enabled") && (targetObject == collider))
                {
                    colliderHides = true;
                }
                else if (!skinShows && (method == "SetActive") && (targetObject == equip.equip.gameObject))
                {
                    skinShows = true;
                }
                else if (!pickupHides && (method == "SetActive") && (targetObject == pickup.worldView.gameObject))
                {
                    pickupHides = true;
                }
            }
        }

        if (equip.equipped == null)
        {
            equip.equipped = new UnityEngine.Events.UnityEvent();
        }

        if (!skinShows)
        {
            UnityEventTools.AddBoolPersistentListener(equip.equipped, new UnityEngine.Events.UnityAction <bool>(equip.equip.gameObject.SetActive), true);
        }
        if (!pickupHides)
        {
            UnityEventTools.AddBoolPersistentListener(equip.equipped, new UnityEngine.Events.UnityAction <bool>(pickup.worldView.gameObject.SetActive), false);
        }
        if (!colliderHides)
        {
            var test = Delegate.CreateDelegate(typeof(UnityEngine.Events.UnityAction <bool>), collider, "set_enabled") as
                       UnityEngine.Events.UnityAction <bool>;

            UnityEventTools.AddBoolPersistentListener(equip.equipped, test, false);
        }
    }
 public void Sim200ms(float dt)
 {
     if (!base.gameObject.HasTag(GameTags.Dead))
     {
         float num  = airConsumptionRate.GetTotalValue() * dt;
         bool  flag = gasProvider.ConsumeGas(this, num);
         if (flag)
         {
             if (gasProvider.ShouldEmitCO2())
             {
                 float num2 = num * O2toCO2conversion;
                 Game.Instance.accumulators.Accumulate(co2Accumulator, num2);
                 accumulatedCO2 += num2;
                 if (accumulatedCO2 >= minCO2ToEmit)
                 {
                     accumulatedCO2 -= minCO2ToEmit;
                     Vector3 position = base.transform.GetPosition();
                     position.x += ((!facing.GetFacing()) ? mouthOffset.x : (0f - mouthOffset.x));
                     position.y += mouthOffset.y;
                     position.z -= 0.5f;
                     CO2Manager.instance.SpawnBreath(position, minCO2ToEmit, temperature.value);
                 }
             }
             else if (gasProvider.ShouldStoreCO2())
             {
                 Equippable equippable = GetComponent <SuitEquipper>().IsWearingAirtightSuit();
                 if ((UnityEngine.Object)equippable != (UnityEngine.Object)null)
                 {
                     float num3 = num * O2toCO2conversion;
                     Game.Instance.accumulators.Accumulate(co2Accumulator, num3);
                     accumulatedCO2 += num3;
                     if (accumulatedCO2 >= minCO2ToEmit)
                     {
                         accumulatedCO2 -= minCO2ToEmit;
                         equippable.GetComponent <Storage>().AddGasChunk(SimHashes.CarbonDioxide, minCO2ToEmit, temperature.value, byte.MaxValue, 0, false, true);
                     }
                 }
             }
         }
         if (flag != hasAir)
         {
             hasAirTimer.Start();
             if (hasAirTimer.TryStop(2f))
             {
                 hasAir = flag;
             }
         }
         else
         {
             hasAirTimer.Stop();
         }
     }
 }
    void HandleItemEquipped(ItemInstance item)
    {
        if (currentEquippedItem != null)
        {
            currentEquippedItem.equipped = false;
            if (!currentEquippedItem.GetComponent <Equippable>().defunct)
            {
                currentEquippedItem.gameObject.GetComponent <FadeInOut>().Stop();
            }
        }

        currentEquippedItem          = item.GetComponent <Equippable>();
        currentEquippedItem.equipped = true;
        currentEquippedItem.gameObject.GetComponent <FadeInOut>().Begin();
        AudioHost._audio.PlayClip(AudioHost.equipItemSound);
    }
Esempio n. 4
0
                private void ProduceSlime(GameObject cougher)
                {
                    AmountInstance amountInstance = Db.Get().Amounts.Temperature.Lookup(cougher);
                    int            gameCell       = Grid.PosToCell(cougher);
                    string         id             = Db.Get().Diseases.SlimeGerms.Id;
                    Equippable     equippable     = base.master.gameObject.GetComponent <SuitEquipper>().IsWearingAirtightSuit();

                    if ((UnityEngine.Object)equippable != (UnityEngine.Object)null)
                    {
                        equippable.GetComponent <Storage>().AddGasChunk(SimHashes.ContaminatedOxygen, 0.1f, amountInstance.value, Db.Get().Diseases.GetIndex(id), 1000, false, true);
                    }
                    else
                    {
                        SimMessages.AddRemoveSubstance(gameCell, SimHashes.ContaminatedOxygen, CellEventLogger.Instance.Cough, 0.1f, amountInstance.value, Db.Get().Diseases.GetIndex(id), 1000, true, -1);
                    }
                    PopFXManager.Instance.SpawnFX(PopFXManager.Instance.sprite_Resource, string.Format(DUPLICANTS.DISEASES.ADDED_POPFX, base.master.modifier.Name, 1000), cougher.transform, 1.5f, false);
                }
Esempio n. 5
0
 public void Display(Equippable obj)
 {
     if (obj == null)
     {
         icon.sprite    = null;
         icon.color     = Color.clear;
         nameLabel.text = "";
         this.obj       = null;
     }
     else
     {
         icon.color          = Color.white;
         icon.preserveAspect = true;
         icon.sprite         = obj.GetComponent <SpriteRenderer>().sprite;
         nameLabel.text      = obj.name;
         this.obj            = obj;
     }
 }
Esempio n. 6
0
        public void SpawnDirtyWater(float dt)
        {
            int   gameCell = Grid.PosToCell(base.sm.worker.Get <KMonoBehaviour>(base.smi));
            byte  index    = Db.Get().Diseases.GetIndex("FoodPoisoning");
            float num      = dt * (0f - bladder.GetDelta()) / bladder.GetMax();

            if (num > 0f)
            {
                float      mass       = 2f * num;
                Equippable equippable = GetComponent <SuitEquipper>().IsWearingAirtightSuit();
                if ((UnityEngine.Object)equippable != (UnityEngine.Object)null)
                {
                    equippable.GetComponent <Storage>().AddLiquid(SimHashes.DirtyWater, mass, bodyTemperature.value, index, Mathf.CeilToInt(100000f * num), false, true);
                }
                else
                {
                    SimMessages.AddRemoveSubstance(gameCell, SimHashes.DirtyWater, CellEventLogger.Instance.Vomit, mass, bodyTemperature.value, index, Mathf.CeilToInt(100000f * num), true, -1);
                }
            }
        }
Esempio n. 7
0
        public static void UnlockSoulbound(Guid character)
        {
            try
            {
                EquipmentSoulbind component;
                Equipment         componentByGuid = Scripts.GetComponentByGuid <Equipment>(character);
                if (!componentByGuid)
                {
                    global::Console.AddMessage("Found no soulbound weapon.", Color.red);
                    return;
                }
                Equippable itemInSlot = componentByGuid.CurrentItems.GetItemInSlot(Equippable.EquipmentSlot.PrimaryWeapon);
                if (!itemInSlot)
                {
                    global::Console.AddMessage("Found no soulbound weapon.", Color.red);
                    return;
                }
                else
                {
                    component = itemInSlot.GetComponent <EquipmentSoulbind>();

                    if (component == null)
                    {
                        global::Console.AddMessage("Found no soulbound weapon.", Color.red);
                        return;
                    }
                }

                IEDebug.Log(string.Format("Found item {0}", component.name));
                mod_EquipmentSoulbind componentAsSoulbind = (mod_EquipmentSoulbind)component;

                componentAsSoulbind.ForceUnlock();
            }
            catch (Exception ex)
            {
                IEDebug.Log(ex.ToString());
                throw new IEModException("Failed to unlock soulbound", ex);
            }
        }
Esempio n. 8
0
    // Is wearing a protective suit
    public Equippable IsWearingProtectiveSuit()
    {
        Equippable     result         = null;
        MinionIdentity minionIdentity = GetComponent <MinionIdentity>();

        if (minionIdentity != null)
        {
            Equipment equipment = minionIdentity.GetEquipment();

            foreach (AssignableSlotInstance assignableSlotInstance in equipment.Slots)
            {
                EquipmentSlotInstance equipmentSlotInstance = (EquipmentSlotInstance)assignableSlotInstance;
                Equippable            equippable            = equipmentSlotInstance.assignable as Equippable;
                if (equippable && equippable.GetComponent <SuitTank>())
                {
                    result = equippable;
                    break;
                }
            }
        }

        return(result);
    }
    private void Emit(object data)
    {
        GameObject gameObject = (GameObject)data;
        float      value      = Db.Get().Amounts.Temperature.Lookup(this).value;
        Equippable equippable = GetComponent <SuitEquipper>().IsWearingAirtightSuit();

        if ((Object)equippable != (Object)null)
        {
            equippable.GetComponent <Storage>().AddGasChunk(SimHashes.Methane, 0.1f, value, byte.MaxValue, 0, false, true);
        }
        else
        {
            Components.Cmps <MinionIdentity> liveMinionIdentities = Components.LiveMinionIdentities;
            Vector2 a = gameObject.transform.GetPosition();
            for (int i = 0; i < liveMinionIdentities.Count; i++)
            {
                MinionIdentity minionIdentity = liveMinionIdentities[i];
                if ((Object)minionIdentity.gameObject != (Object)gameObject.gameObject)
                {
                    Vector2 b   = minionIdentity.transform.GetPosition();
                    float   num = Vector2.SqrMagnitude(a - b);
                    if (num <= 2.25f)
                    {
                        minionIdentity.Trigger(508119890, Strings.Get("STRINGS.DUPLICANTS.DISEASES.PUTRIDODOUR.CRINGE_EFFECT").String);
                        minionIdentity.gameObject.GetSMI <ThoughtGraph.Instance>().AddThought(Db.Get().Thoughts.PutridOdour);
                    }
                }
            }
            int gameCell = Grid.PosToCell(gameObject.transform.GetPosition());
            SimMessages.AddRemoveSubstance(gameCell, SimHashes.Methane, CellEventLogger.Instance.ElementConsumerSimUpdate, 0.1f, value, byte.MaxValue, 0, true, -1);
            KBatchedAnimController kBatchedAnimController = FXHelpers.CreateEffect("odor_fx_kanim", gameObject.transform.GetPosition(), gameObject.transform, true, Grid.SceneLayer.Front, false);
            kBatchedAnimController.Play(WorkLoopAnims, KAnim.PlayMode.Once);
            kBatchedAnimController.destroyOnAnimComplete = true;
        }
        KFMOD.PlayOneShot(GlobalAssets.GetSound("Dupe_Flatulence", false), base.transform.GetPosition());
    }
    private void PickUpHorseGear(Player player, equippableItemID itemToTake)
    {
        Equippable combined = null;
        Equippable halter   = null;
        Equippable lead     = null;

        if (equippable.id == equippableItemID.HALTER_WITH_LEAD)
        {
            combined = equippable;
            foreach (Transform child in equippable.transform)
            {
                Equippable childEquippable = child.GetComponent <Equippable> ();
                if (childEquippable.id == equippableItemID.HALTER)
                {
                    halter = childEquippable;
                }
                else if (childEquippable.id == equippableItemID.LEAD)
                {
                    lead = childEquippable;
                }
            }
        }

        switch (itemToTake)
        {
        case equippableItemID.HALTER:
            //if content.id is halter and lead, but i only want to take halter, unparent lead and halter from halter_w_lead. take halter, lead remains
            if (equippable.id == equippableItemID.HALTER_WITH_LEAD)
            {
                halter.BeEquipped();
                player.EquipAnItem(halter);
                combined.transform.SetParent(halter.transform);
                lead.transform.SetParent(null);
                lead.GetComponent <SphereCollider> ().enabled = true;
            }
            else if (equippable.id == equippableItemID.HALTER)
            {
                PickUpAll(player);
            }
            break;

        case equippableItemID.LEAD:
            //if content.id is halter and lead, but i only want to take halter, unparent lead and halter from halter_w_lead. take lead, halter remains
            if (equippable.id == equippableItemID.HALTER_WITH_LEAD)
            {
                lead.BeEquipped();
                player.EquipAnItem(lead);
                halter.transform.SetParent(null);
                combined.transform.SetParent(halter.transform);
                halter.GetComponent <SphereCollider> ().enabled   = true;
                combined.GetComponent <SphereCollider> ().enabled = false;
            }
            else if (equippable.id == equippableItemID.LEAD)
            {
                PickUpAll(player);
            }
            break;

        case equippableItemID.HALTER_WITH_LEAD:
            PickUpAll(player);
            break;
        }
    }
Esempio n. 11
0
        public static void ChangeClass(string guid, string charclass)
        {
            GameObject npc      = null;
            string     charname = guid.Replace("_", " ");

            foreach (var partymember in PartyMemberAI.PartyMembers)
            {
                if (partymember != null && RemoveDiacritics(partymember.gameObject.GetComponent <CharacterStats>().Name()).Contains(charname))
                {
                    npc = partymember.gameObject;
                }
            }
            if (npc == null)
            {
                npc = UnityEngine.GameObject.Find(guid);
            }
            if (npc != null)
            {
                bool goOn = false;
                try
                {
                    if (Enum.Parse(typeof(CharacterStats.Class), charclass) != null)
                    {
                        goOn = true;
                    }
                }
                catch
                {
                    global::Console.AddMessage(charclass + " - not found as a class.");
                }
                if (goOn)
                {
                    object newclassobj = Enum.Parse(typeof(CharacterStats.Class), charclass);
                    int    newclassId  = Convert.ToInt32(newclassobj);

                    List <string> Innates = new List <string>();

                    //Put all innate non-racial talents and abilities here (case insensitive):
                    Innates.Add("crucible_of_the_soul");
                    Innates.Add("armed_to_the_teeth");
                    Innates.Add("speaker_to_the_restless");
                    Innates.Add("dominion_of_the_sleepers");
                    Innates.Add("steps_to_the_wheel");
                    Innates.Add("Beraths_Boon");
                    Innates.Add("Hyleas_Boon");
                    Innates.Add("Waels_Boon");
                    Innates.Add("Galawains_Boon");
                    Innates.Add("Rymrgands_Boon");
                    Innates.Add("Skaens_Boon");
                    Innates.Add("Second_Skin");
                    Innates.Add("The_Merciless_Hand");
                    Innates.Add("Mob_Justice");
                    Innates.Add("Mob Justice");                     //the ability has a space in place of an underscore...
                    Innates.Add("Blooded_Hunter");
                    Innates.Add("Song_of_the_Heavens");
                    Innates.Add("Wild_Running");
                    Innates.Add("Dungeon_Delver");
                    Innates.Add("Scale-Breaker");
                    Innates.Add("Gift_from_the_Machine");
                    Innates.Add("Effigys_Resentment");                     //should work for all types

                    if (npc.GetComponent <CharacterStats>().name.Contains("Sagani"))
                    {
                        Innates.Add("SummonCompanionArcticFox");
                    }

                    //==========================================================================
                    //REMOVE TALENTS
                    //==========================================================================
                    List <GenericTalent> talentRemoveList = new List <GenericTalent>();
                    foreach (GenericTalent activeTalent in npc.GetComponent <CharacterStats>().ActiveTalents)
                    {
                        bool saveMe = false;
                        foreach (string innate in Innates)
                        {
                            if (activeTalent.gameObject.name.IndexOf(innate, StringComparison.OrdinalIgnoreCase) >= 0)                             //look for substring
                            {
                                saveMe = true;
                                break;
                            }
                        }
                        if (!saveMe)
                        {
                            talentRemoveList.Add(activeTalent);
                        }
                    }
                    foreach (GenericTalent talentToRemove in talentRemoveList)
                    {
                        AbilityProgressionTable.RemoveAbilityFromCharacter(talentToRemove.gameObject, npc.GetComponent <CharacterStats>());
                    }

                    talentRemoveList.Clear();
                    foreach (GenericTalent talent in npc.GetComponent <CharacterStats>().Talents)
                    {
                        bool saveMe = false;
                        foreach (string innate in Innates)
                        {
                            if (talent.gameObject.name.IndexOf(innate, StringComparison.OrdinalIgnoreCase) >= 0)                             //look for substring
                            {
                                saveMe = true;
                                break;
                            }
                        }
                        if (!saveMe)
                        {
                            talentRemoveList.Add(talent);
                        }
                    }
                    foreach (GenericTalent talentToRemove in talentRemoveList)
                    {
                        AbilityProgressionTable.RemoveAbilityFromCharacter(talentToRemove.gameObject, npc.GetComponent <CharacterStats>());
                    }
                    //==========================================================================

                    //==========================================================================
                    //REMOVE ABILITIES
                    //==========================================================================
                    List <GenericAbility> abilRemoveList = new List <GenericAbility>();
                    foreach (GenericAbility activeAbility in npc.GetComponent <CharacterStats>().ActiveAbilities)
                    {
                        if (activeAbility.EffectType == GenericAbility.AbilityType.Racial)
                        {
                            continue;
                        }
                        bool saveMe = false;
                        foreach (string innate in Innates)
                        {
                            if (activeAbility.gameObject.name.IndexOf(innate, StringComparison.OrdinalIgnoreCase) >= 0)                             //look for substring
                            {
                                saveMe = true;
                                break;
                            }
                        }
                        if (!saveMe)
                        {
                            abilRemoveList.Add(activeAbility);
                        }
                    }
                    foreach (GenericAbility abilToRemove in abilRemoveList)
                    {
                        abilToRemove.ForceDeactivate(npc);
                        AbilityProgressionTable.RemoveAbilityFromCharacter(abilToRemove.gameObject, npc.GetComponent <CharacterStats>());
                    }
                    abilRemoveList.Clear();
                    foreach (GenericAbility ability in npc.GetComponent <CharacterStats>().Abilities)
                    {
                        if (ability.EffectType == GenericAbility.AbilityType.Racial)
                        {
                            continue;
                        }
                        bool saveMe = false;
                        foreach (string innate in Innates)
                        {
                            if (ability.gameObject.name.IndexOf(innate, StringComparison.OrdinalIgnoreCase) >= 0)                             //look for substring
                            {
                                saveMe = true;
                                break;
                            }
                        }
                        if (!saveMe)
                        {
                            abilRemoveList.Add(ability);
                        }
                    }
                    foreach (GenericAbility abilToRemove in abilRemoveList)
                    {
                        abilToRemove.ForceDeactivate(npc);
                        AbilityProgressionTable.RemoveAbilityFromCharacter(abilToRemove.gameObject, npc.GetComponent <CharacterStats>());
                    }
                    //==========================================================================

                    // remove ranger's pet
                    if (npc.GetComponent <CharacterStats>().CharacterClass == CharacterStats.Class.Ranger && !npc.GetComponent <CharacterStats>().name.Contains("Sagani"))
                    {
                        foreach (var cre in npc.GetComponent <AIController>().SummonedCreatureList)
                        {
                            if (GameUtilities.IsAnimalCompanion(cre.gameObject))
                            {
                                PartyMemberAI.RemoveFromActiveParty(cre.GetComponent <PartyMemberAI>(), true);
                                cre.GetComponent <Persistence>().UnloadsBetweenLevels = true;
                                cre.GetComponent <Health>().m_isAnimalCompanion       = false;
                                cre.GetComponent <Health>().ApplyDamageDirectly(1000);
                                cre.GetComponent <Health>().ApplyDamageDirectly(1000);
                                global::Console.AddMessage(cre.GetComponent <CharacterStats>().Name() + " is free from its bonds and returns to the wilds to be with its own kind.", Color.green);
                                cre.SetActive(false);
                            }
                        }
                        //npc.GetComponent<AIController> ().SummonedCreatureList.Clear ();
                    }

                    // remove or give grimoire
                    if (npc.GetComponent <CharacterStats>().CharacterClass != (CharacterStats.Class)newclassId)
                    {
                        if (npc.GetComponent <CharacterStats>().CharacterClass == CharacterStats.Class.Wizard)
                        {
                            npc.GetComponent <Equipment>().UnEquip(Equippable.EquipmentSlot.Grimoire);
                        }

                        npc.GetComponent <CharacterStats>().CharacterClass = (CharacterStats.Class)newclassId;

                        if (npc.GetComponent <CharacterStats>().CharacterClass == CharacterStats.Class.Wizard)
                        {
                            // equip an empty grimoire...?
                            Equippable grim = GameResources.LoadPrefab <Equippable>("empty_grimoire_01", true);
                            if (grim != null)
                            {
                                grim.GetComponent <Grimoire>().PrimaryOwnerName = npc.GetComponent <CharacterStats>().Name();
                                npc.GetComponent <Equipment>().Equip(grim);
                            }
                        }
                    }

                    //BaseDeflection,BaseFortitude,BaseReflexes,BaseWill,MeleeAccuracyBonus,RangedAccuracyBonus,MaxHealth,MaxStamina,HealthStaminaPerLevel,ClassHealthMultiplier
                    object comp = (object)npc.GetComponent <CharacterStats>();
                    DataManager.AdjustFromData(ref comp);

                    npc.GetComponent <CharacterStats>().Level = 0;

                    npc.GetComponent <CharacterStats>().StealthSkill   = 0;
                    npc.GetComponent <CharacterStats>().StealthBonus   = 0;
                    npc.GetComponent <CharacterStats>().AthleticsSkill = 0;
                    npc.GetComponent <CharacterStats>().AthleticsBonus = 0;
                    npc.GetComponent <CharacterStats>().LoreSkill      = 0;
                    npc.GetComponent <CharacterStats>().LoreBonus      = 0;
                    npc.GetComponent <CharacterStats>().MechanicsSkill = 0;
                    npc.GetComponent <CharacterStats>().MechanicsBonus = 0;
                    npc.GetComponent <CharacterStats>().SurvivalSkill  = 0;
                    npc.GetComponent <CharacterStats>().SurvivalBonus  = 0;

                    npc.GetComponent <CharacterStats>().RemainingSkillPoints = 0;

                    string HeOrShe = npc.GetComponent <CharacterStats>().Gender.ToString();
                    global::Console.AddMessage(npc.GetComponent <CharacterStats>().Name() + " has reformed into a " + charclass + ". " + (HeOrShe == "Male" ? "He" : "She") + " lost all " + (HeOrShe == "Male" ? "his" : "her") + " previous abilities and talents.", Color.green);
                }
            }
            else
            {
                global::Console.AddMessage("Couldn't find: " + guid, Color.yellow);
            }
        }
        // changing oxygen breather to accumulate oxygen
        public static void Postfix(OxygenBreather __instance, ref float dt)
        {
            if (!__instance.gameObject.HasTag(GameTags.Dead))
            {
                float num = Traverse.Create(__instance).Field("airConsumptionRate").Method("GetTotalValue").GetValue <float>() * dt;

                bool flag = Traverse.Create(__instance).Field("gasProvider").Method("ConsumeGas", __instance, num).GetValue <bool>();
                if (flag)
                {
                    // add oxygen to storage
                    __instance.GetComponents <Storage>()[1].AddGasChunk(SimHashes.Oxygen, num, Traverse.Create(__instance).Field("temperature").Field("value").GetValue <float>(), byte.MaxValue, 0, false, true);

                    if (Traverse.Create(__instance).Field("gasProvider").Method("ShouldEmitCO2").GetValue <bool>())
                    {
                        float num2 = num * __instance.O2toCO2conversion;

                        Game.Instance.accumulators.Accumulate(Traverse.Create(__instance).Field("co2Accumulator").GetValue <HandleVector <int> .Handle>(), num2);
                        __instance.accumulatedCO2 += num2;
                        if (__instance.accumulatedCO2 >= __instance.minCO2ToEmit)
                        {
                            GameObject     o2Chunk          = __instance.GetComponents <Storage>()[1].FindFirst(SimHashes.Oxygen.CreateTag());
                            PrimaryElement primaryElementO2 = o2Chunk.GetComponent <PrimaryElement>();
                            primaryElementO2.Mass -= o2_fraction_of_co2 * __instance.minCO2ToEmit;

                            __instance.accumulatedCO2 -= __instance.minCO2ToEmit;
                            Vector3 position = __instance.transform.GetPosition();
                            position.x += ((!Traverse.Create(__instance).Field("facing").GetValue <Facing>().GetFacing()) ? __instance.mouthOffset.x : (-__instance.mouthOffset.x));
                            position.y += __instance.mouthOffset.y;
                            position.z -= 0.5f;
                            CO2Manager.instance.SpawnBreath(position, __instance.minCO2ToEmit, Traverse.Create(__instance).Field("temperature").Field("value").GetValue <float>());
                        }
                    }
                    else if (Traverse.Create(__instance).Field("gasProvider").Method("ShouldStoreCO2").GetValue <bool>())
                    {
                        Equippable equippable = __instance.GetComponent <SuitEquipper>().IsWearingAirtightSuit();
                        if (equippable != null)
                        {
                            float num3 = num * __instance.O2toCO2conversion;
                            Game.Instance.accumulators.Accumulate(Traverse.Create(__instance).Field("co2Accumulator").GetValue <HandleVector <int> .Handle>(), num3);
                            __instance.accumulatedCO2 += num3;
                            if (__instance.accumulatedCO2 >= __instance.minCO2ToEmit)
                            {
                                GameObject     o2Chunk          = __instance.GetComponents <Storage>()[1].FindFirst(SimHashes.Oxygen.CreateTag());
                                PrimaryElement primaryElementO2 = o2Chunk.GetComponent <PrimaryElement>();
                                primaryElementO2.KeepZeroMassObject = true;                            // makes sure the mass doesn't go negative
                                primaryElementO2.Mass -= o2_fraction_of_co2 * __instance.minCO2ToEmit; // subtract o2 in co2 from oxygen storage

                                __instance.accumulatedCO2 -= __instance.minCO2ToEmit;
                                equippable.GetComponent <Storage>().AddGasChunk(SimHashes.CarbonDioxide, __instance.minCO2ToEmit, Traverse.Create(__instance).Field("temperature").Field("value").GetValue <float>(), byte.MaxValue, 0, false, true);
                            }
                        }
                    }
                }
                if (flag != Traverse.Create(__instance).Field("hasAir").GetValue <bool>())
                {
                    Traverse.Create(__instance).Field("hasAirTimer").Method("Start").GetValue();
                    if (Traverse.Create(__instance).Field("hasAirTimer").Method("TryStop", 2f).GetValue <bool>())
                    {
                        Traverse.Create(__instance).Field("hasAir").SetValue(flag);
                    }
                }
                else
                {
                    Traverse.Create(__instance).Field("hasAirTimer").Method("Stop").GetValue();
                }
            }
        }
Esempio n. 13
0
    private void Update()
    {
        if (allowPlayerInput)
        {
            //---------MOVEMENT---------//
            //GetAxis returns value between -1 and 1
            movementVectorInput.x = Input.GetAxisRaw("Horizontal");
            movementVectorInput.z = Input.GetAxisRaw("Vertical");

            if (currentMovementSet == playerMovementSet.WALKING)
            {
                newMovementVector = getMovementVector(movementVectorInput);
            }
            else if (currentMovementSet == playerMovementSet.RIDING)
            {
                float desiredTurnRate;
                if (nearestHorse.horseBehavior.isAvoidingCollider)
                {
                    desiredTurnRate = maximumTurnRate * (nearestHorse.horseBehavior.shouldAvoidInPositiveDirection ? -1.0f : 1.0f);
                }
                else
                {
                    desiredTurnRate = movementVectorInput.x * maximumTurnRate;
                }
                newMovementVector = getMovementVector(desiredTurnRate);
            }

            destination = transform.position + newMovementVector;
            if (newMovementVector.magnitude > 0)
            {
                transform.LookAt(new Vector3(destination.x, transform.position.y, destination.z));
            }
            rb.MovePosition(rb.position + newMovementVector);

            if (currentMovementSet == playerMovementSet.WALKING)
            {
                if (currentlyEquippedItem != null && currentlyEquippedItem.preventSprintingWhileEquipped)
                {
                    speedMultiplier = currentlyEquippedItem.playerSpeedModifier;
                }
                else if (Input.GetKey(KeyCode.LeftShift))
                {
                    speedMultiplier = sprintSpeedMultiplier;
                }
                else
                {
                    speedMultiplier = 1f;
                }

                if (currentlyEquippedItem != null && currentlyEquippedItem.id == equippableItemID.HORSE_ON_LEAD)
                {
                    //Debug.Log ("movement magnitude: " + newMovementVector.magnitude);

                    if (nearestHorse == null)
                    {
                        nearestHorse = currentlyEquippedItem.GetComponent <Horse> ();
                    }

                    if (newMovementVector.magnitude > 0)
                    {
                        if (Input.GetKey(KeyCode.LeftShift))
                        {
                            nearestHorse.horseBehavior.currentHorseGait = horseGait.TROT;
                        }
                        else
                        {
                            nearestHorse.horseBehavior.currentHorseGait = horseGait.WALK;
                        }
                    }
                    else
                    {
                        nearestHorse.horseBehavior.currentHorseGait = horseGait.STAND;
                    }
                }

                //------INTERACTION-------//

                if (nearestInteractable != null)
                {
                    //Debug.Log ("there is nearest int " + nearestInteractable.name + " (parent: " + nearestInteractable.transform.parent + "). arrowinput " + nearestInteractable.arrowInputRequired);

                    if (Input.GetKeyDown(KeyCode.E) && nearestInteractable.arrowInputRequired == null)
                    {
                        //Debug.Log ("pressed E with nearest int input required == null");

                        nearestInteractable.PlayerInteracts(this);
                        // ^ This can mean that nearestInteractable is set to null because of PutIntoInventory --> ExitInteractionTrigger.

                        //check if that is the case, and don't finish the updae if so.
                        if (nearestInteractable == null)
                        {
                            return;
                        }

                        UI.instance.ShowInstruction(nearestInteractable, this);
                    }

                    if (nearestInteractable.arrowInputRequired != null)
                    {
                        if (Input.GetKeyDown(KeyCode.LeftArrow))
                        {
                            nearestInteractable.PlayerPressesArrow(this, dir.LEFT);
                        }
                        else if (Input.GetKeyDown(KeyCode.DownArrow))
                        {
                            nearestInteractable.PlayerPressesArrow(this, dir.DOWN);
                        }
                        else if (Input.GetKeyDown(KeyCode.RightArrow))
                        {
                            nearestInteractable.PlayerPressesArrow(this, dir.RIGHT);
                        }
                        else if (Input.GetKeyDown(KeyCode.UpArrow))
                        {
                            nearestInteractable.PlayerPressesArrow(this, dir.UP);
                        }
                    }

                    if (nearestInteractable.currentlyRelevantActionIDs.Count > 1)
                    {
                        if (Input.GetKeyDown(KeyCode.R))
                        {
                            ++nearestInteractable.selectedInteractionIndex;
                            if (nearestInteractable.selectedInteractionIndex == nearestInteractable.currentlyRelevantActionIDs.Count)
                            {
                                nearestInteractable.selectedInteractionIndex = 0;
                            }
                            UI.instance.ShowInstruction(nearestInteractable, this);
                        }
                    }
                }

                //-----------INVENTORY---------//
                mouseWheelInput = Input.GetAxis("Mouse ScrollWheel");
                if (mouseWheelInput != 0)
                {
                    inventory.ScrollInput(mouseWheelInput);
                }
            }

            //------RIDING-------//
            if (currentMovementSet == playerMovementSet.RIDING)
            {
                speedMultiplier = nearestHorse.horseRidingBehavior.actualMovementSpeedMultiplier;
                nearestHorse.horseRidingBehavior.currentTotalMovementSpeed = speed * speedMultiplier;

                //Debug.Log("SPEED: " + speed * speedMultiplier + " GOTO " + newMovementVector/Time.deltaTime);

                if (nearestHorse.horseBehavior.currentHorseGait != horseGait.STAND && newMovementVector.magnitude == 0)
                {
                    nearestHorse.horseBehavior.currentHorseGait = horseGait.STAND;
                }

                if (Input.GetKeyDown(KeyCode.S))
                {
                    nearestHorse.horseRidingBehavior.ReceivePlayerInput(this, dir.LEFT);
                }
                else if (Input.GetKeyDown(KeyCode.Q))
                {
                    nearestHorse.horseRidingBehavior.ReceivePlayerInput(this, dir.DOWN);
                }
                else if (Input.GetKeyDown(KeyCode.W))
                {
                    nearestHorse.horseRidingBehavior.ReceivePlayerInput(this, dir.RIGHT);
                }
                else if (Input.GetKeyDown(KeyCode.E))
                {
                    nearestHorse.horseRidingBehavior.ReceivePlayerInput(this, dir.UP);
                }

                if (previousMovementVector.magnitude > 0 && newMovementVector.magnitude == 0 /*&& !keepHorseMoving*/)
                {
                    nearestHorse.horseRidingBehavior.ReceivePlayerInput(this, dir.DOWN, true);
                    //	ridingHorse.horseBehaviour.currentHorseGait = horseGait.STAND;
                }
                else if (previousMovementVector.magnitude == 0 && newMovementVector.magnitude > 0)
                {
                    Debug.Log("horse was standing, starts moving now");
                    nearestHorse.horseBehavior.currentHorseGait = horseGait.WALK;
                    nearestHorse.horseRidingBehavior.ReceivePlayerInput(this, dir.UP, true);
                }
            }

            previousMovementVector = newMovementVector;

            if (Input.GetKeyDown(KeyCode.F) && currentlyEquippedItem != playerHands)
            {
                DropEquippedItem();
            }

            if (Input.GetKeyDown(KeyCode.J))
            {
                //Open/Close Quests/Journal
                Debug.Log("qu instance name " + Quests.instance.name);
                Debug.Log("qui GO name " + Quests.instance.questUI.gameObject.name + ". is visible: " + Quests.instance.questUIVisible);
                Quests.instance.questUI.ShowQuestUI(!Quests.instance.questUIVisible);
            }

            if (Input.GetKeyDown(KeyCode.H))
            {
                Debug.Log("pressed H. help visible: " + helpVisible);
                UI.instance.helpUI.SetActive(!helpVisible);
                helpVisible = !helpVisible;
            }
        }
        else
        {
            if (Input.GetMouseButtonDown(0) && UI.instance.dialogueIsVisible)
            {
                UI.instance.ContinueInDialogue();
            }
        }
    }
Esempio n. 14
0
    public void Equip(Equippable equippable)
    {
        AssignableSlotInstance slot = GetSlot(equippable.slot);

        slot.Assign(equippable);
        GameObject targetGameObject = GetTargetGameObject();

        Debug.Assert(targetGameObject, "GetTargetGameObject returned null in Equip");
        targetGameObject.Trigger(-448952673, equippable.GetComponent <KPrefabID>());
        equippable.Trigger(-1617557748, this);
        Attributes attributes = targetGameObject.GetAttributes();

        if (attributes != null)
        {
            foreach (AttributeModifier attributeModifier in equippable.def.AttributeModifiers)
            {
                attributes.Add(attributeModifier);
            }
        }
        SnapOn component = targetGameObject.GetComponent <SnapOn>();

        if ((Object)component != (Object)null)
        {
            component.AttachSnapOnByName(equippable.def.SnapOn);
            if (equippable.def.SnapOn1 != null)
            {
                component.AttachSnapOnByName(equippable.def.SnapOn1);
            }
        }
        KBatchedAnimController component2 = targetGameObject.GetComponent <KBatchedAnimController>();

        if ((Object)component2 != (Object)null && (Object)equippable.def.BuildOverride != (Object)null)
        {
            component2.GetComponent <SymbolOverrideController>().AddBuildOverride(equippable.def.BuildOverride.GetData(), equippable.def.BuildOverridePriority);
        }
        if ((bool)equippable.transform.parent)
        {
            Storage component3 = equippable.transform.parent.GetComponent <Storage>();
            if ((bool)component3)
            {
                component3.Drop(equippable.gameObject, true);
            }
        }
        equippable.transform.parent = slot.gameObject.transform;
        equippable.transform.SetLocalPosition(Vector3.zero);
        SetEquippableStoredModifiers(equippable, true);
        equippable.OnEquip(slot);
        if (refreshHandle.TimeRemaining > 0f)
        {
            Debug.LogWarning(targetGameObject.GetProperName() + " is already in the process of changing equipment (equip)");
            refreshHandle.ClearScheduler();
        }
        CreatureSimTemperatureTransfer transferer = targetGameObject.GetComponent <CreatureSimTemperatureTransfer>();

        if (!((Object)component2 == (Object)null))
        {
            refreshHandle = GameScheduler.Instance.Schedule("ChangeEquipment", 2f, delegate
            {
                if ((Object)transferer != (Object)null)
                {
                    transferer.RefreshRegistration();
                }
            }, null, null);
        }
        Game.Instance.Trigger(-2146166042, null);
    }
Esempio n. 15
0
    public void Unequip(Equippable equippable)
    {
        AssignableSlotInstance slot = GetSlot(equippable.slot);

        slot.Unassign(true);
        equippable.Trigger(-170173755, this);
        GameObject targetGameObject = GetTargetGameObject();

        if ((bool)targetGameObject)
        {
            targetGameObject.Trigger(-1285462312, equippable.GetComponent <KPrefabID>());
            KBatchedAnimController component = targetGameObject.GetComponent <KBatchedAnimController>();
            if (!destroyed)
            {
                if ((Object)equippable.def.BuildOverride != (Object)null && (Object)component != (Object)null)
                {
                    component.GetComponent <SymbolOverrideController>().TryRemoveBuildOverride(equippable.def.BuildOverride.GetData(), equippable.def.BuildOverridePriority);
                }
                Attributes attributes = targetGameObject.GetAttributes();
                if (attributes != null)
                {
                    foreach (AttributeModifier attributeModifier in equippable.def.AttributeModifiers)
                    {
                        attributes.Remove(attributeModifier);
                    }
                }
                if (!equippable.def.IsBody)
                {
                    SnapOn component2 = targetGameObject.GetComponent <SnapOn>();
                    component2.DetachSnapOnByName(equippable.def.SnapOn);
                    if (equippable.def.SnapOn1 != null)
                    {
                        component2.DetachSnapOnByName(equippable.def.SnapOn1);
                    }
                }
                if ((bool)equippable.transform.parent)
                {
                    Storage component3 = equippable.transform.parent.GetComponent <Storage>();
                    if ((bool)component3)
                    {
                        component3.Drop(equippable.gameObject, true);
                    }
                }
                SetEquippableStoredModifiers(equippable, false);
                equippable.transform.parent = null;
                equippable.transform.SetPosition(targetGameObject.transform.GetPosition() + Vector3.up / 2f);
                KBatchedAnimController component4 = equippable.GetComponent <KBatchedAnimController>();
                if ((bool)component4)
                {
                    component4.SetSceneLayer(Grid.SceneLayer.Ore);
                }
                if (!((Object)component == (Object)null))
                {
                    if (refreshHandle.TimeRemaining > 0f)
                    {
                        refreshHandle.ClearScheduler();
                    }
                    refreshHandle = GameScheduler.Instance.Schedule("ChangeEquipment", 1f, delegate
                    {
                        GameObject gameObject = (!((Object)this != (Object)null)) ? null : GetTargetGameObject();
                        if ((bool)gameObject)
                        {
                            CreatureSimTemperatureTransfer component5 = gameObject.GetComponent <CreatureSimTemperatureTransfer>();
                            if ((Object)component5 != (Object)null)
                            {
                                component5.RefreshRegistration();
                            }
                        }
                    }, null, null);
                }
            }
            Game.Instance.Trigger(-2146166042, null);
        }
    }