public CombatExtendedUtil(World world) : base(world)
 {
     Ammo?.Clear();
     if (Ammo == null)
     {
         Ammo = new Dictionary <ThingDef, int>();
     }
 }
示例#2
0
            static void Prefix()
            {
                if (Levels.IsLevel(Levels.WORLD))
                {
                    Transform  playerLoc = SceneContext.Instance.Player.transform;
                    RewardData reward;
                    if (rewardsQueue.TryDequeue(out reward))
                    {
                        switch (reward.action)
                        {
                        case "sound":
                            break;

                        case "inventory_bomb":
                            Ammo ammo = SceneContext.Instance.PlayerState.Ammo;
                            foreach (Slot s in (Slot[])Traverse.Create(ammo).Property("Slots").GetValue())
                            {
                                if (s == null)
                                {
                                    continue;
                                }
                                for (int i = 0; i < s.count; i++)
                                {
                                    GameObject   slotObject = GameContext.Instance.LookupDirector.GetPrefab(s.id);
                                    RegionMember region     = (RegionMember)Traverse.Create(SceneContext.Instance.PlayerZoneTracker).Field("member").GetValue();
                                    GameObject   gameObject = SRBehaviour.InstantiateActor(slotObject, region.setId, playerLoc.position + playerLoc.forward * 0.5f, playerLoc.rotation, false);
                                    Rigidbody    component  = gameObject.GetComponent <Rigidbody>();
                                    component.AddForce((playerLoc.forward * 100f + UnityEngine.Random.insideUnitSphere * 100f) * component.mass);
                                }
                            }
                            ammo.Clear();
                            break;
                        }
                    }
                }
            }
            static void Prefix()
            {
                if (Levels.IsLevel(Levels.WORLD) && SRInput.Instance.GetInputMode() == SRInput.InputMode.DEFAULT)
                {
                    DateTime     currentTime  = DateTime.UtcNow;
                    SceneContext sceneContext = SRSingleton <SceneContext> .Instance;
                    Transform    playerLoc    = SceneContext.Instance.Player.transform;
                    PlayerState  playerState  = SceneContext.Instance.PlayerState;
                    RewardData   reward;
                    if (rewardsQueue.TryDequeue(out reward))
                    {
                        switch (reward.action)
                        {
                        case "sound":
                            break;

                        case "inventory_bomb":
                            Ammo ammo = playerState.Ammo;
                            foreach (Slot s in (Slot[])Traverse.Create(ammo).Property("Slots").GetValue())
                            {
                                if (s == null)
                                {
                                    continue;
                                }
                                for (int i = 0; i < s.count; i++)
                                {
                                    spawnObject(s.id, playerLoc);
                                }
                            }
                            ammo.Clear();
                            break;

                        case "meteor_shower":
                            break;

                        case "downgrade_plot":
                            int duration;
                            int.TryParse(reward.args[0], out duration);
                            int numPlots;
                            int.TryParse(reward.args[1], out numPlots);
                            bool removeAllWalls;
                            bool.TryParse(reward.args[2], out removeAllWalls);
                            delayedDowngrades.Add(new DelayedDowngrade(numPlots, duration, removeAllWalls));
                            break;

                        case "spawn_object":
                            int objectID;
                            int.TryParse(reward.args[0], out objectID);
                            int ammount;
                            int.TryParse(reward.args[1], out ammount);
                            if (Enum.IsDefined(typeof(Identifiable.Id), objectID))
                            {
                                Identifiable.Id obj = (Identifiable.Id)objectID;
                                for (int i = 0; i < ammount; i++)
                                {
                                    spawnObject(obj, playerLoc);
                                }
                            }
                            else
                            {
                                Debug.LogError("Could not spawn in object with the ID of " + objectID + ". INVALID ID!");
                            }
                            break;

                        case "push_player":
                            float pushMin = 0.1f;
                            float.TryParse(reward.args[0], out pushMin);
                            float pushMax = 0.3f;
                            float.TryParse(reward.args[1], out pushMax);
                            if (push)
                            {
                                pushData.left += 8;
                            }
                            else
                            {
                                push     = true;
                                pushData = new PushData(pushMin, pushMax, currentTime, 250);
                            }
                            break;

                        case "adjust_money":
                            int amountToAdjust;
                            int.TryParse(reward.args[0], out amountToAdjust);
                            if (amountToAdjust < 0)
                            {
                                if (playerState.GetCurrency() < amountToAdjust)
                                {
                                    amountToAdjust = playerState.GetCurrency();
                                }
                                playerState.SpendCurrency(amountToAdjust);
                            }
                            else
                            {
                                playerState.AddCurrency(amountToAdjust);
                            }
                            break;

                        case "shoot_gun":
                            WeaponVacuum vacuum = sceneContext.Player.GetComponentInChildren <WeaponVacuum>();
                            Traverse.Create(vacuum).Method("Expel", new HashSet <GameObject>()).GetValue();
                            break;

                        case "day_night":
                            float hour = sceneContext.TimeDirector.CurrHour();
                            if (hour > 6 && hour < 18)
                            {
                                sceneContext.TimeDirector.FastForwardTo(sceneContext.TimeDirector.GetHourAfter(0, 18f));
                            }
                            else
                            {
                                sceneContext.TimeDirector.FastForwardTo(sceneContext.TimeDirector.GetNextDawn());
                            }
                            break;

                        case "stat_edit":
                            string type   = reward.args[0];
                            string action = reward.args[1];
                            int    amount;
                            int.TryParse(reward.args[2], out amount);
                            if (type.Equals("health"))
                            {
                                switch (action)
                                {
                                case "add":
                                    playerState.SetHealth(Math.Min(playerState.GetCurrHealth() + amount, playerState.GetMaxHealth()));
                                    break;

                                case "sub":
                                    playerState.SetHealth(Math.Max(playerState.GetCurrHealth() - amount, 1));
                                    break;

                                case "max":
                                    playerState.SetHealth(playerState.GetMaxHealth());
                                    break;

                                case "set":
                                    playerState.SetHealth(amount);
                                    break;
                                }
                            }
                            else if (type.Equals("energy"))
                            {
                                switch (action)
                                {
                                case "add":
                                    playerState.SetEnergy(Math.Min(playerState.GetCurrEnergy() + amount, playerState.GetMaxEnergy()));
                                    break;

                                case "sub":
                                    playerState.SetEnergy(Math.Max(playerState.GetCurrEnergy() - amount, 0));
                                    break;

                                case "max":
                                    playerState.SetEnergy(playerState.GetMaxEnergy());
                                    break;

                                case "set":
                                    playerState.SetEnergy(amount);
                                    break;
                                }
                            }
                            else if (type.Equals("rads"))
                            {
                                switch (action)
                                {
                                case "add":
                                    playerState.SetRad(playerState.GetCurrRad() + amount);
                                    break;

                                case "sub":
                                    playerState.SetRad(Math.Max(playerState.GetCurrRad() - amount, 0));
                                    break;

                                case "set":
                                    playerState.SetRad(amount);
                                    break;
                                }
                            }

                            break;
                        }
                    }

                    for (int i = plotsEdited.Count - 1; i >= 0; i--)
                    {
                        UpgradeHolder plot = plotsEdited[i];
                        if ((currentTime - plot.Spawned).TotalMilliseconds > plot.Duration)
                        {
                            plotsEdited.RemoveAt(i);
                            plot.Reset();
                        }
                    }

                    if (push)
                    {
                        try
                        {
                            sceneContext.Player.transform.position += pushData.push;
                        }
                        catch
                        {
                            Debug.LogError("PLAYER (or related) IS NULL! Unable to push the player!");
                        }
                        if ((currentTime - pushData.startTime).TotalMilliseconds > pushData.duration)
                        {
                            pushData.left--;
                            if (pushData.left == 0)
                            {
                                push = false;
                            }
                            else
                            {
                                pushData.startTime = currentTime;
                                pushData.nextPush();
                            }
                        }
                    }

                    for (int i = delayedDowngrades.Count - 1; i >= 0; i--)
                    {
                        DelayedDowngrade dd = delayedDowngrades[i];

                        List <LandPlotModel> validplots = new List <LandPlotModel>();
                        //this.GetComponentInParent<Region>();
                        int corralPlots = 0;
                        foreach (LandPlotModel plot in sceneContext.GameModel.AllLandPlots().Values)
                        {
                            if (plot.typeId == LandPlot.Id.CORRAL)
                            {
                                corralPlots++;
                                if (Vector3.Distance(sceneContext.Player.transform.position, ((GameObject)Traverse.Create(plot).Field("gameObj").GetValue()).transform.position) < 100)
                                {
                                    validplots.Add(plot);
                                }
                            }
                        }

                        if (corralPlots != 0 && validplots.Count == 0)
                        {
                            continue;
                        }

                        delayedDowngrades.RemoveAt(i);

                        while (validplots.Count > 0 && dd.numPlots != 0)
                        {
                            LandPlotModel plotModel = validplots.ToArray()[UnityEngine.Random.Range(0, validplots.Count())];
                            validplots.Remove(plotModel);
                            dd.numPlots--;
                            LandPlot plot = ((GameObject)Traverse.Create(plotModel).Field("gameObj").GetValue()).GetComponentInChildren <LandPlot>();
                            HashSet <LandPlot.Upgrade> upgrades = new HashSet <LandPlot.Upgrade>();
                            foreach (PlotUpgrader component in plot.GetComponents <PlotUpgrader>())
                            {
                                if (component is AirNetUpgrader && plot.HasUpgrade(LandPlot.Upgrade.AIR_NET))
                                {
                                    upgrades.Add(LandPlot.Upgrade.AIR_NET);
                                    foreach (GameObject airNet in ((AirNetUpgrader)component).airNets)
                                    {
                                        airNet.SetActive(false);
                                    }
                                }
                                else if (component is SolarShieldUpgrader && plot.HasUpgrade(LandPlot.Upgrade.SOLAR_SHIELD))
                                {
                                    upgrades.Add(LandPlot.Upgrade.SOLAR_SHIELD);
                                    foreach (GameObject shield in ((SolarShieldUpgrader)component).shields)
                                    {
                                        shield.SetActive(false);
                                    }
                                }
                                else if (component is WallUpgrader && plot.HasUpgrade(LandPlot.Upgrade.WALLS))
                                {
                                    upgrades.Add(LandPlot.Upgrade.WALLS);
                                    ((WallUpgrader)component).standardWalls.SetActive(!dd.removeAllWalls);
                                    ((WallUpgrader)component).upgradeWalls.SetActive(false);
                                }
                                plotsEdited.Add(new UpgradeHolder(plot, upgrades, dd.duration * 1000));
                            }
                        }
                    }
                }
            }