Beispiel #1
0
        /// <summary> Called when the entity has received damage, but after armor damage reduction was applied </summary>
        public float OnDamageAfterArmor(float damage, DamageSource source)
        {
            float newDamage = damage;
            int   effectivePewterBurnStatus = Helper.GetEffectiveBurnStatus("pewter");

            if (effectivePewterBurnStatus > 0 && source.Type != EnumDamageType.Heal)
            {
                float reductionAmount = (1f / 5.0f * effectivePewterBurnStatus);
                float reducedDamage   = damage * reductionAmount;
                newDamage -= reducedDamage;
                Helper.IncreasePewterFatigue(reducedDamage * 2);
                Helper.IncrementMetalReserve("pewter", -reducedDamage / 4);
            }
            EntityBehaviorHealth health = (EntityBehaviorHealth)entity.GetBehavior("health");

            if (newDamage > health.Health)
            {
                if (Helper.GetPower("pewter") && source.Type != EnumDamageType.Heal)
                {
                    if (Helper.GetMetalReserve("pewter") > 0)
                    {
                        Helper.SetBurnToggle("pewter", true);
                        Helper.IncrementBurnStatus("pewter", 1);
                        Helper.IncreasePewterFatigue(newDamage * Helper.GetEffectiveBurnStatus("pewter"));
                        Helper.IncrementMetalReserve("pewter", -newDamage);
                        if (Helper.GetMetalReserve("pewter") != 0)
                        {
                            newDamage = health.Health / 2;
                        }
                    }
                }
            }
            if (source.SourceEntity != null)
            {
                if (source.SourceEntity.HasBehavior("allomancy"))
                {
                    EntityBehaviorAllomancy enemyAllomancy = (EntityBehaviorAllomancy)source.SourceEntity.GetBehavior("allomancy");
                    int effectiveEnemyChromiumBurnStatus   = enemyAllomancy.Helper.GetEffectiveBurnStatus("chromium");
                    if (effectiveEnemyChromiumBurnStatus > 0)
                    {
                        Helper.ClearAllReserves();
                    }
                }
            }
            return(newDamage);
        }
Beispiel #2
0
        /// <summary> Initialize the client handler. </summary>
        public void Initialize()
        {
            // Register the networking channel.
            Channel = Capi.Network.RegisterChannel(MistModSystem.MOD_ID)
                      .RegisterMessageType(typeof(BurnMessage))
                      .RegisterMessageType(typeof(SelectedMetalMessage))
                      .RegisterMessageType(typeof(ReplaceAlloHelperEntity));

            Channel.SetMessageHandler <SelectedMetalMessage>(OnSelectedMetalMessage);
            Channel.SetMessageHandler <ReplaceAlloHelperEntity>(OnUpdateAlloHelper);

            // Hotkeys for burning metals.
            Capi.Input.RegisterHotKey("burn-metal-toggle",
                                      "Toggle allomantic metal burn",
                                      GlKeys.Z,
                                      HotkeyType.CharacterControls,
                                      false,
                                      true,
                                      true);
            Capi.Input.RegisterHotKey(
                "burn-metal-inc",
                "Increase allomantic metal burn",
                GlKeys.Z,
                HotkeyType.CharacterControls,
                false,
                false,
                true);
            Capi.Input.RegisterHotKey(
                "burn-metal-dec",
                "Decrease allomantic metal burn",
                GlKeys.Z,
                HotkeyType.CharacterControls,
                false,
                true,
                false);
            Capi.Input.RegisterHotKey(
                "burn-metal-flare",
                "Flare allomantic metal",
                GlKeys.Z,
                HotkeyType.CharacterControls);

            Capi.Input.SetHotKeyHandler("burn-metal-toggle", a => {
                Channel.SendPacket(new BurnMessage(metalSelector.SelectedMetal, 4));
                return(true);
            });
            Capi.Input.SetHotKeyHandler("burn-metal-inc", a => {
                Channel.SendPacket(new BurnMessage(metalSelector.SelectedMetal, 3));
                return(true);
            });
            Capi.Input.SetHotKeyHandler("burn-metal-dec", a => {
                Channel.SendPacket(new BurnMessage(metalSelector.SelectedMetal, 2));
                return(true);
            });
            Capi.Input.SetHotKeyHandler("burn-metal-flare", a => {
                Channel.SendPacket(new BurnMessage(metalSelector.SelectedMetal, 1));
                return(true);
            });

            // Hotkeys for GUI
            Capi.Input.RegisterHotKey(
                "guimetalselect",
                "Select allomantic metal",
                GlKeys.K,
                HotkeyType.GUIOrOtherControls);

            Capi.Input.SetHotKeyHandler("guimetalselect", ToggleMetalSelectGui);

            // Add event to know when the game has loaded.
            Capi.Event.BlockTexturesLoaded += OnLoad;

            // Create an allomancy helper for the entity.
            Capi.Event.LevelFinalize += () => {
                AllomancyHelper = new AllomancyPropertyHelper(Capi.World.Player.Entity);
            };

            // Register UI updates
            Capi.Event.RegisterGameTickListener((float dt) => {
                AllomancyHelper.Entity = Capi.World.Player.Entity;
                AllomancyHelper.UpdateTree();
                if (AllomancyHelper != null)
                {
                    metalSelector.UpdateUI(dt);
                }
            }, 10);

            motionParticles.gravityEffect = 0;

            // Visual effects updates
            Capi.Event.RegisterGameTickListener((float dt) => {
                if (AllomancyHelper != null)
                {
                    float maxhealth = ((ITreeAttribute)Capi.World.Player.Entity.WatchedAttributes["health"]).GetFloat("maxhealth");
                    float fatigue   = AllomancyHelper.GetPewterFatigue();
                    targetVignete   = fatigue / maxhealth;
                    if (targetVignete > 1)
                    {
                        targetVignete = 1;
                    }
                    ShaderLoader.VigneteStrength += (targetVignete - ShaderLoader.VigneteStrength) / 5;
                    int tinstatus     = AllomancyHelper.GetEffectiveBurnStatus("tin");
                    targetNightvision = tinstatus * (1.0f / 5.0f);
                    ShaderLoader.NightvisionStrength += (targetNightvision - ShaderLoader.NightvisionStrength) / 5;
                }
            }, 0);
            Capi.Event.RegisterGameTickListener((float dt) => {
                int tinstatus = AllomancyHelper.GetEffectiveBurnStatus("tin");
                if (previousTinStatus == 0 && tinstatus != 0)
                {
                    Capi.Settings.Int["cachedfov"] = Capi.Settings.Int["fieldOfView"];
                }
                if (tinstatus == 0 && previousTinStatus != 0)
                {
                    if (Capi.Settings.Int["cachedfov"] != 0)
                    {
                        Capi.Settings.Int["fieldOfView"] = Capi.Settings.Int["cachedfov"];
                    }
                }
                if (tinstatus > 0)
                {
                    Capi.Settings.Int["fieldOfView"] = 100 - tinstatus * 18;
                    motionParticles.glowLevel        = (byte)(255.0f * tinstatus * (1.0f / 5.0f));
                    float vspeed                  = 3.0f * tinstatus * (1.0f / 5.0f) + 0.1f;
                    motionParticles.minSize       = 3.0f * tinstatus * (1.0f / 5.0f) + 1f;
                    motionParticles.maxSize       = 3.0f * tinstatus * (1.0f / 5.0f) + 1f;
                    motionParticles.minVelocity.Y = vspeed;
                    Entity[] nearbyEnts           = Capi.World.GetEntitiesAround(Capi.World.Player.Entity.Pos.XYZ, 100, 100);
                    foreach (Entity ent in nearbyEnts)
                    {
                        if (ent == Capi.World.Player.Entity)
                        {
                            continue;
                        }
                        motionParticles.minPos = ent.Pos.XYZ;
                        Capi.World.SpawnParticles(motionParticles);
                    }
                }
                previousTinStatus = tinstatus;
            }, 100);
        }