public static CrowdResponse RemoveStardrop(ControlClient client, CrowdRequest req)
        {
            CrowdResponse.Status status = CrowdResponse.Status.STATUS_SUCCESS;
            string message = "";

            int stamina = Game1.player.MaxStamina;

            if (stamina == 270)
            {
                status  = CrowdResponse.Status.STATUS_FAILURE;
                message = Game1.player.Name + " is already at lowest energy maximum";
            }
            else
            {
                stamina -= 34;
                Game1.player.MaxStamina = stamina;
                if (Game1.player.Stamina > stamina)
                {
                    Game1.player.Stamina = stamina;
                }
                UI.ShowInfo($"{req.GetReqViewer()} removed a Stardrop from {Game1.player.Name}");
            }

            return(new CrowdResponse(req.GetReqID(), status, message));
        }
        private static CrowdResponse DoUpgrade(CrowdRequest req, string toolName, int max = 4)
        {
            CrowdResponse.Status status = CrowdResponse.Status.STATUS_SUCCESS;
            string message = "";

            Tool tool = Game1.player.getToolFromName(toolName);

            if (tool == null)
            {
                status  = CrowdResponse.Status.STATUS_FAILURE;
                message = $"{Game1.player.Name}'s {toolName} is already at the highest upgrade level";
            }
            else
            {
                int level = tool.UpgradeLevel;
                if (level == max)
                {
                    status = CrowdResponse.Status.STATUS_FAILURE;
                }
                else
                {
                    tool.UpgradeLevel = level + 1;
                    UI.ShowInfo($"{req.GetReqViewer()} upgraded {Game1.player.Name}'s {toolName}");
                }
            }

            return(new CrowdResponse(req.GetReqID(), status, message));
        }
        public static CrowdResponse DowngradeBoots(ControlClient client, CrowdRequest req)
        {
            CrowdResponse.Status status = CrowdResponse.Status.STATUS_SUCCESS;
            string message = "";

            StardewBoots boots = Game1.player.boots.Get();

            if (boots == null)
            {
                status  = CrowdResponse.Status.STATUS_FAILURE;
                message = Game1.player.Name + " is not currently wearing Boots";
            }
            else
            {
                boots = Boots.GetDowngrade(boots.getStatsIndex());
                if (boots == null)
                {
                    status  = CrowdResponse.Status.STATUS_FAILURE;
                    message = Game1.player.Name + "'s Boots are already at the lowest upgrade level";
                }
                else
                {
                    Game1.player.boots.Value = boots;
                    Game1.player.changeShoeColor(boots.indexInColorSheet);
                    UI.ShowInfo($"{req.GetReqViewer()} downgraded {Game1.player.Name}'s Boots");
                }
            }

            return(new CrowdResponse(req.GetReqID(), status, message));
        }
        public static CrowdResponse UpgradeWeapon(ControlClient client, CrowdRequest req)
        {
            int id = req.GetReqID();

            if (WeaponClass.Club.DoUpgrade() || WeaponClass.Sword.DoUpgrade() || WeaponClass.Dagger.DoUpgrade())
            {
                UI.ShowInfo($"{req.GetReqViewer()} upgraded {Game1.player.Name}'s Weapon");
                return(new CrowdResponse(id));
            }

            return(new CrowdResponse(id, CrowdResponse.Status.STATUS_FAILURE, Game1.player.Name + "'s Weapon is already at the highest upgrade level"));
        }
        public static CrowdResponse Kill(ControlClient client, CrowdRequest req)
        {
            CrowdResponse.Status status = CrowdResponse.Status.STATUS_SUCCESS;
            string message = "";

            if (Interlocked.Exchange(ref Game1.player.health, 0) == 0)
            {
                status  = CrowdResponse.Status.STATUS_FAILURE;
                message = Game1.player.Name + " is currently dead";
            }
            else
            {
                UI.ShowInfo($"{req.GetReqViewer()} killed {Game1.player.Name}");
            }

            return(new CrowdResponse(req.GetReqID(), status, message));
        }
示例#6
0
        public void RequestLoop()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            while (Running)
            {
                try
                {
                    while (Saving || Game1.isTimePaused)
                    {
                        Thread.Yield();
                    }

                    CrowdRequest req = null;
                    lock (Requests)
                    {
                        if (Requests.Count == 0)
                        {
                            continue;
                        }
                        req = Requests.Dequeue();
                    }

                    string code = req.GetReqCode();
                    try
                    {
                        CrowdResponse res = Delegate[code](this, req);
                        if (res == null)
                        {
                            new CrowdResponse(req.GetReqID(), CrowdResponse.Status.STATUS_FAILURE, $"Request error for '{code}'").Send(Socket);
                        }

                        res.Send(Socket);
                    }
                    catch (KeyNotFoundException)
                    {
                        new CrowdResponse(req.GetReqID(), CrowdResponse.Status.STATUS_FAILURE, $"Request error for '{code}'").Send(Socket);
                    }
                }
                catch (Exception)
                {
                    UI.ShowError("Disconnected from Crowd Control");
                    Socket.Close();
                }
            }
        }
        public static CrowdResponse DowngradeFishingRod(ControlClient client, CrowdRequest req)
        {
            int id = req.GetReqID();

            foreach (KeyValuePair <string, int> downgrade in downgradeFishingRods)
            {
                Tool tool = Game1.player.getToolFromName(downgrade.Key);
                if (tool != null)
                {
                    tool.UpgradeLevel = downgrade.Value;
                    UI.ShowInfo($"{req.GetReqViewer()} downgraded {Game1.player.Name}'s Fishing Rod");

                    return(new CrowdResponse(id));
                }
            }

            return(new CrowdResponse(id, CrowdResponse.Status.STATUS_FAILURE, Game1.player.Name + "'s Fishing Rod is already at the lowest upgrade level"));
        }
        public static CrowdResponse UpgradeTrashCan(ControlClient client, CrowdRequest req)
        {
            CrowdResponse.Status status = CrowdResponse.Status.STATUS_SUCCESS;
            string message = "";

            if (Game1.player.trashCanLevel < 4)
            {
                Interlocked.Increment(ref Game1.player.trashCanLevel);
                UI.ShowInfo($"{req.GetReqViewer()} upgraded {Game1.player.Name}'s Trash Can");
            }
            else
            {
                status  = CrowdResponse.Status.STATUS_FAILURE;
                message = Game1.player.Name + "'s Trash Can is already at the highest upgrade level";
            }

            return(new CrowdResponse(req.GetReqID(), status, message));
        }
        public static CrowdResponse UpgradeBackpack(ControlClient client, CrowdRequest req)
        {
            CrowdResponse.Status status = CrowdResponse.Status.STATUS_SUCCESS;
            string message = "";

            if (Game1.player.items.Capacity == 36)
            {
                status  = CrowdResponse.Status.STATUS_FAILURE;
                message = Game1.player.Name + "'s Backpack is already at maximum capacity";
            }
            else
            {
                Game1.player.increaseBackpackSize(12);
                UI.ShowInfo($"{req.GetReqViewer()} upgraded {Game1.player.Name}'s Backpack");
            }

            return(new CrowdResponse(req.GetReqID(), status, message));
        }
        private static CrowdResponse DoSpawn(ControlClient client, CrowdRequest req, Monster monster)
        {
            CrowdResponse.Status status = CrowdResponse.Status.STATUS_SUCCESS;
            string message = "";

            if (client.CanSpawn())
            {
                Game1.player.currentLocation.addCharacter(monster);
                client.TrackMonster(monster);
                UI.ShowInfo($"{req.GetReqViewer()} spawned a {monster.Name} near {Game1.player.Name}");
            }
            else
            {
                status  = CrowdResponse.Status.STATUS_FAILURE;
                message = $"Cannot spawn {monster.Name} because {Game1.player.Name} is at {Game1.player.currentLocation.Name}";
            }

            return(new CrowdResponse(req.GetReqID(), status, message));
        }
        private static CrowdResponse DoHurtBy(CrowdRequest req, float percent)
        {
            CrowdResponse.Status status = CrowdResponse.Status.STATUS_SUCCESS;
            string message = "";

            int health = Game1.player.health - (int)Math.Floor(percent * Game1.player.maxHealth);

            if (Interlocked.Exchange(ref Game1.player.health, (health < 0) ? 0 : health) == 0)
            {
                Game1.player.health = 0;
                status  = CrowdResponse.Status.STATUS_FAILURE;
                message = Game1.player.Name + " is already dead";
            }
            else
            {
                UI.ShowInfo($"{req.GetReqViewer()} hurt {Game1.player.Name} by {(int)Math.Floor(100 * percent)}%");
            }

            return(new CrowdResponse(req.GetReqID(), status, message));
        }
        public static CrowdResponse PassOut(ControlClient client, CrowdRequest req)
        {
            CrowdResponse.Status status = CrowdResponse.Status.STATUS_SUCCESS;
            string message = "";

            float stamina = Game1.player.Stamina;

            if (stamina > -16)
            {
                Game1.player.Stamina = -16;
                UI.ShowInfo($"{req.GetReqViewer()} made {Game1.player.Name} pass out");
            }
            else
            {
                status  = CrowdResponse.Status.STATUS_FAILURE;
                message = Game1.player.Name + " is currently passed out";
            }

            return(new CrowdResponse(req.GetReqID(), status, message));
        }
        private static CrowdResponse DoRemoveMoney(CrowdRequest req, int amount)
        {
            CrowdResponse.Status status = CrowdResponse.Status.STATUS_SUCCESS;
            string message = "";

            int money = Game1.player.Money;

            if (money > 0)
            {
                money -= amount;
                Game1.player.Money = (money < 0) ? 0 : money;
                UI.ShowInfo($"{req.GetReqViewer()} removed {amount} coins from {Game1.player.Name}");
            }
            else
            {
                status  = CrowdResponse.Status.STATUS_FAILURE;
                message = Game1.player.Name + " currently has no money";
            }

            return(new CrowdResponse(req.GetReqID(), status, message));
        }
        private static CrowdResponse DoTireBy(CrowdRequest req, float percent)
        {
            CrowdResponse.Status status = CrowdResponse.Status.STATUS_SUCCESS;
            string message = "";

            float stamina = Game1.player.Stamina;

            if (stamina > 0)
            {
                stamina -= percent * Game1.player.MaxStamina;
                Game1.player.Stamina = (stamina < 0) ? 0 : stamina;
                UI.ShowInfo($"{req.GetReqViewer()} tired {Game1.player.Name} by {(int)Math.Floor(100 * percent)}%");
            }
            else
            {
                status  = CrowdResponse.Status.STATUS_FAILURE;
                message = Game1.player.Name + " is already passed out";
            }

            return(new CrowdResponse(req.GetReqID(), status, message));
        }
        public static CrowdResponse EnergizeFull(ControlClient client, CrowdRequest req)
        {
            CrowdResponse.Status status = CrowdResponse.Status.STATUS_SUCCESS;
            string message = "";

            int   max     = Game1.player.MaxStamina;
            float stamina = Game1.player.Stamina;

            if (stamina < max)
            {
                Game1.player.Stamina = max;
                UI.ShowInfo($"{req.GetReqViewer()} fully energized {Game1.player.Name}");
            }
            else
            {
                status  = CrowdResponse.Status.STATUS_FAILURE;
                message = Game1.player.Name + " is already at maximum energy";
            }

            return(new CrowdResponse(req.GetReqID(), status, message));
        }
 private static CrowdResponse DoWarp(CrowdRequest req, string name, int targetX, int targetY)
 {
     try
     {
         Game1.player.resetState();
         Game1.warpFarmer(name, targetX, targetY, false);
     }
     catch (Exception e)
     {
         UI.ShowError(e.Message);
     }
     if (name == "Forest")
     {
         name = "Wizard's Tower";
     }
     else if (name == "IslandSouth")
     {
         name = "Island";
     }
     UI.ShowInfo($"{req.GetReqViewer()} warped {Game1.player.Name} to the {name}");
     return(new CrowdResponse(req.GetReqID()));
 }
        private static CrowdResponse DoEnergizeBy(CrowdRequest req, float percent)
        {
            CrowdResponse.Status status = CrowdResponse.Status.STATUS_SUCCESS;
            string message = "";

            int   max     = Game1.player.MaxStamina;
            float stamina = Game1.player.Stamina;

            if (stamina < max)
            {
                stamina += percent * max;
                Game1.player.Stamina = (stamina > max) ? max : stamina;
                UI.ShowInfo($"{req.GetReqViewer()} energized {Game1.player.Name} by {(int)Math.Floor(100 * percent)}%");
            }
            else
            {
                status  = CrowdResponse.Status.STATUS_FAILURE;
                message = Game1.player.Name + " is already at maximum energy";
            }

            return(new CrowdResponse(req.GetReqID(), status, message));
        }
        public static CrowdResponse GiveStardrop(ControlClient client, CrowdRequest req)
        {
            CrowdResponse.Status status = CrowdResponse.Status.STATUS_SUCCESS;
            string message = "";

            int stamina = Game1.player.MaxStamina;

            if (stamina == 508)
            {
                status  = CrowdResponse.Status.STATUS_FAILURE;
                message = Game1.player.Name + " is already at the highest energy maximum";
            }
            else
            {
                stamina += 34;
                Game1.player.MaxStamina = stamina;
                Game1.player.Stamina    = stamina;
                UI.ShowInfo($"{req.GetReqViewer()} gave {Game1.player.Name} a Stardrop");
            }

            return(new CrowdResponse(req.GetReqID(), status, message));
        }
示例#19
0
        private void ClientLoop()
        {
            UI.ShowInfo("Connected to Crowd Control");

            try
            {
                while (Running)
                {
                    CrowdRequest req = CrowdRequest.Recieve(this, Socket);
                    if (req == null || req.IsKeepAlive())
                    {
                        continue;
                    }

                    lock (Requests)
                        Requests.Enqueue(req);
                }
            }
            catch (Exception)
            {
                UI.ShowError("Disconnected from Crowd Control");
                Socket.Close();
            }
        }
 public static CrowdResponse WarpFarm(ControlClient client, CrowdRequest req)
 {
     return(DoWarp(req, "Farm", 48, 7));
 }
 public static CrowdResponse DowngradeAxe(ControlClient client, CrowdRequest req)
 {
     return(DoDowngrade(req, "Axe"));
 }
 public static CrowdResponse WarpMountain(ControlClient client, CrowdRequest req)
 {
     return(DoWarp(req, "Mountain", 31, 20));
 }
 public static CrowdResponse WarpIsland(ControlClient client, CrowdRequest req)
 {
     return(DoWarp(req, "IslandSouth", 11, 11));
 }
 public static CrowdResponse WarpSewer(ControlClient client, CrowdRequest req)
 {
     return(DoWarp(req, "Sewer", 16, 13));
 }
 public static CrowdResponse WarpRailroad(ControlClient client, CrowdRequest req)
 {
     return(DoWarp(req, "Railroad", 35, 52));
 }
 public static CrowdResponse WarpTower(ControlClient client, CrowdRequest req)
 {
     return(DoWarp(req, "Forest", 5, 29));
 }
 private static CrowdResponse DoGiveMoney(CrowdRequest req, int amount)
 {
     Game1.player.addUnearnedMoney(amount);
     UI.ShowInfo($"{req.GetReqViewer()} gave {Game1.player.Name} {amount} coins");
     return(new CrowdResponse(req.GetReqID()));
 }
 private static CrowdResponse DoGiveBuff(CrowdRequest req, int buff, int duration, string name)
 {
     new Thread(new BuffThread(buff, duration * 1000).Run).Start();
     UI.ShowInfo($"{req.GetReqViewer()} gave {Game1.player.Name} the {name} effect for {duration} seconds");
     return(new CrowdResponse(req.GetReqID()));
 }
 public static CrowdResponse WarpTown(ControlClient client, CrowdRequest req)
 {
     return(DoWarp(req, "Town", 29, 67));
 }
 public static CrowdResponse WarpWoods(ControlClient client, CrowdRequest req)
 {
     return(DoWarp(req, "Woods", 55, 15));
 }