示例#1
0
 public static void BotDebug(string s, params object[] args)
 {
     if (Game.Settings.Debug.BotDebug)
     {
         TextNotificationsManager.Debug(s, args);
     }
 }
示例#2
0
        public void ResolveOrder(Actor self, Order order)
        {
            if (!Enabled)
            {
                return;
            }

            switch (order.OrderString)
            {
            case "Taunt":
            {
                if (self.World.LocalPlayer != null)
                {
                    var rules = self.World.Map.Rules;
                    if (rules.Notifications["taunts"].NotificationsPools.Value.ContainsKey(order.TargetString))
                    {
                        Game.Sound.PlayNotification(rules, self.World.LocalPlayer, "Taunts", order.TargetString, self.Owner.Faction.InternalName);
                    }
                    else
                    {
                        TextNotificationsManager.Debug("{0} is not a valid taunt.", order.TargetString);
                    }
                }

                break;
            }
            }
        }
示例#3
0
        public Actor[] ActivateParatroopers(WPos target, int facing = -1)
        {
            TextNotificationsManager.Debug("SendParatroopersFrom is deprecated. Use TargetParatroopers instead.");
            var actors = pp.SendParatroopers(Self, target, facing == -1 ? (WAngle?)null : WAngle.FromFacing(facing));

            return(actors.Aircraft);
        }
        void Delete(string savePath)
        {
            try
            {
                File.Delete(savePath);
            }
            catch (Exception ex)
            {
                TextNotificationsManager.Debug("Failed to delete save file '{0}'. See the logs for details.", savePath);
                Log.Write("debug", ex.ToString());
                return;
            }

            if (savePath == selectedSave)
            {
                Select(null);
            }

            var item = gameList.Children
                       .Select(c => c as ScrollItemWidget)
                       .FirstOrDefault(c => c.ItemKey == savePath);

            gameList.RemoveChild(item);
            games.Remove(savePath);
        }
示例#5
0
        public void SendAirstrikeFrom(CPos from, CPos to)
        {
            TextNotificationsManager.Debug("SendAirstrikeFrom is deprecated. Use TargetAirstrike instead.");
            var i = Self.World.Map.CenterOfCell(from);
            var j = Self.World.Map.CenterOfCell(to);

            ap.SendAirstrike(Self, j, (i - j).Yaw);
        }
示例#6
0
        public void Debug(string text)
        {
            if (string.IsNullOrEmpty(text) || !Game.Settings.Debug.LuaDebug)
            {
                return;
            }

            TextNotificationsManager.Debug(text);
        }
示例#7
0
 static Order CheckSameOrder(IOrderTargeter iot, Order order)
 {
     if (order == null && iot.OrderID != null)
     {
         TextNotificationsManager.Debug("BUG: in order targeter - decided on {0} but then didn't order", iot.OrderID);
     }
     else if (order != null && iot.OrderID != order.OrderString)
     {
         TextNotificationsManager.Debug("BUG: in order targeter - decided on {0} but ordered {1}", iot.OrderID, order.OrderString);
     }
     return(order);
 }
示例#8
0
        public void InvokeCommand(string name, string arg)
        {
            TextNotificationsManager.Debug("Here are the available commands:");

            foreach (var key in console.Commands.Keys)
            {
                if (!helpDescriptions.TryGetValue(key, out var description))
                {
                    description = "no description available.";
                }

                TextNotificationsManager.Debug("{0}: {1}", key, description);
            }
        }
示例#9
0
        string DeleteMap(string map)
        {
            try
            {
                modData.MapCache[map].Delete();
                if (selectedUid == map)
                {
                    selectedUid = Game.ModData.MapCache.ChooseInitialMap(tabMaps[currentTab].Select(mp => mp.Uid).FirstOrDefault(),
                                                                         Game.CosmeticRandom);
                }
            }
            catch (Exception ex)
            {
                TextNotificationsManager.Debug("Failed to delete map '{0}'. See the debug.log file for details.", map);
                Log.Write("debug", ex.ToString());
            }

            return(selectedUid);
        }
示例#10
0
        public bool OnChat(string playername, string message)
        {
            if (message.StartsWith("/"))
            {
                var name    = message.Substring(1).Split(' ')[0].ToLowerInvariant();
                var command = Commands.FirstOrDefault(x => x.Key == name);

                if (command.Value != null)
                {
                    command.Value.InvokeCommand(name.ToLowerInvariant(), message.Substring(1 + name.Length).Trim());
                }
                else
                {
                    TextNotificationsManager.Debug("{0} is not a valid command.", name);
                }

                return(false);
            }

            return(true);
        }
示例#11
0
        public void InvokeCommand(string name, string arg)
        {
            switch (name)
            {
            case "taunt":
                if (!taunts.Enabled)
                {
                    TextNotificationsManager.Debug("Taunts are disabled.");
                    return;
                }

                if (world.LocalPlayer != null)
                {
                    world.IssueOrder(new Order("Taunt", world.LocalPlayer.PlayerActor, false)
                    {
                        TargetString = arg
                    });
                }

                break;
            }
        }
示例#12
0
        public void ParseCommand(Actor self, string message)
        {
            var command = message.Split(' ')[0].ToLowerInvariant();

            switch (command)
            {
            case "body":
                turret  = -1;
                enabled = true;
                break;

            case "turret":
                int turretIndex;
                var parse = int.TryParse(message.Split(' ')[1], out turretIndex);
                turret  = !parse || turretIndex >= turrets.Length ? -1 : turretIndex;
                enabled = true;
                break;

            case "set":
                var setoffsets = message.Split(' ')[1].Split(',');
                if (setoffsets.Length != 3)
                {
                    break;
                }

                var setoffset = new int[3];
                for (var i = 0; i < setoffsets.Length; i++)
                {
                    _ = int.TryParse(setoffsets[i], out setoffset[i]);
                }

                devOffset = new WVec(setoffset[0], setoffset[1], setoffset[2]);
                enabled   = true;
                break;

            case "add":
                var addoffsets = message.Split(' ')[1].Split(',');
                if (addoffsets.Length != 3)
                {
                    break;
                }

                var addoffset = new int[3];
                for (var i = 0; i < addoffsets.Length; i++)
                {
                    _ = int.TryParse(addoffsets[i], out addoffset[i]);
                }

                devOffset += new WVec(addoffset[0], addoffset[1], addoffset[2]);
                enabled    = true;
                break;

            case "query":
                TextNotificationsManager.Debug("The current DevOffset on actor {0} {1} is: {2},{3},{4}", self.Info.Name, self.ActorID, devOffset.X, devOffset.Y, devOffset.Z);
                break;

            case "disable":
                enabled = false;
                break;

            default:
                break;
            }
        }
示例#13
0
        public void ResolveOrder(Actor self, Order order)
        {
            if (!Enabled)
            {
                return;
            }

            var debugSuffix = "";

            switch (order.OrderString)
            {
            case "DevAll":
            {
                enableAll ^= true;
                allTech    = fastCharge = fastBuild = disableShroud = unlimitedPower = buildAnywhere = enableAll;

                if (enableAll)
                {
                    self.Owner.Shroud.ExploreAll();

                    var amount = order.ExtraData != 0 ? (int)order.ExtraData : info.Cash;
                    self.Trait <PlayerResources>().ChangeCash(amount);
                }
                else
                {
                    self.Owner.Shroud.ResetExploration();
                }

                self.Owner.Shroud.Disabled = DisableShroud;
                if (self.World.LocalPlayer == self.Owner)
                {
                    self.World.RenderPlayer = DisableShroud ? null : self.Owner;
                }

                break;
            }

            case "DevEnableTech":
            {
                allTech ^= true;
                break;
            }

            case "DevFastCharge":
            {
                fastCharge ^= true;
                break;
            }

            case "DevFastBuild":
            {
                fastBuild ^= true;
                break;
            }

            case "DevGiveCash":
            {
                var amount = order.ExtraData != 0 ? (int)order.ExtraData : info.Cash;
                self.Trait <PlayerResources>().ChangeCash(amount);

                debugSuffix = $" ({amount} credits)";
                break;
            }

            case "DevGiveCashAll":
            {
                var amount           = order.ExtraData != 0 ? (int)order.ExtraData : info.Cash;
                var receivingPlayers = self.World.Players.Where(p => p.Playable);

                foreach (var player in receivingPlayers)
                {
                    player.PlayerActor.Trait <PlayerResources>().ChangeCash(amount);
                }

                debugSuffix = $" ({amount} credits)";
                break;
            }

            case "DevGrowResources":
            {
                foreach (var a in self.World.ActorsWithTrait <ISeedableResource>())
                {
                    for (var i = 0; i < info.ResourceGrowth; i++)
                    {
                        a.Trait.Seed(a.Actor);
                    }
                }

                break;
            }

            case "DevVisibility":
            {
                disableShroud ^= true;
                self.Owner.Shroud.Disabled = DisableShroud;
                if (self.World.LocalPlayer == self.Owner)
                {
                    self.World.RenderPlayer = DisableShroud ? null : self.Owner;
                }

                break;
            }

            case "DevPathDebug":
            {
                pathDebug ^= true;
                break;
            }

            case "DevGiveExploration":
            {
                self.Owner.Shroud.ExploreAll();
                break;
            }

            case "DevResetExploration":
            {
                self.Owner.Shroud.ResetExploration();
                break;
            }

            case "DevUnlimitedPower":
            {
                unlimitedPower ^= true;
                break;
            }

            case "DevBuildAnywhere":
            {
                buildAnywhere ^= true;
                break;
            }

            case "DevPlayerExperience":
            {
                self.Owner.PlayerActor.TraitOrDefault <PlayerExperience>()?.GiveExperience((int)order.ExtraData);
                break;
            }

            case "DevKill":
            {
                if (order.Target.Type != TargetType.Actor)
                {
                    break;
                }

                var actor       = order.Target.Actor;
                var args        = order.TargetString.Split(' ');
                var damageTypes = BitSet <DamageType> .FromStringsNoAlloc(args);

                actor.Kill(actor, damageTypes);
                break;
            }

            case "DevDispose":
            {
                if (order.Target.Type != TargetType.Actor)
                {
                    break;
                }

                order.Target.Actor.Dispose();
                break;
            }

            default:
                return;
            }

            TextNotificationsManager.Debug("Cheat used: {0} by {1}{2}", order.OrderString, self.Owner.PlayerName, debugSuffix);
        }
示例#14
0
 public void SendAirstrike(WPos target, bool randomize = true, int facing = 0)
 {
     TextNotificationsManager.Debug("SendAirstrike is deprecated. Use TargetAirstrike instead.");
     ap.SendAirstrike(Self, target, randomize ? (WAngle?)null : WAngle.FromFacing(facing));
 }
示例#15
0
        ActorInit CreateInit(string initName, LuaValue value)
        {
            // Find the requested type
            var initInstance = initName.Split(ActorInfo.TraitInstanceSeparator);
            var initType     = Game.ModData.ObjectCreator.FindType(initInstance[0] + "Init");

            if (initType == null)
            {
                throw new LuaException($"Unknown initializer type '{initInstance[0]}'");
            }

            // Construct the ActorInit.
            var init = (ActorInit)FormatterServices.GetUninitializedObject(initType);

            if (initInstance.Length > 1)
            {
                initType.GetField(nameof(ActorInit.InstanceName)).SetValue(init, initInstance[1]);
            }

            if (value is LuaTable tableValue && init is CompositeActorInit compositeInit)
            {
                var args       = compositeInit.InitializeArgs();
                var initValues = new Dictionary <string, object>();
                foreach (var kv in tableValue)
                {
                    using (kv.Key)
                        using (kv.Value)
                        {
                            var key = kv.Key.ToString();
                            if (!args.TryGetValue(key, out var type))
                            {
                                throw new LuaException($"Unknown initializer type '{initInstance[0]}.{key}'");
                            }

                            var isActorReference = type == typeof(ActorInitActorReference);
                            if (isActorReference)
                            {
                                type = kv.Value is LuaString ? typeof(string) : typeof(Actor);
                            }

                            if (!kv.Value.TryGetClrValue(type, out var clrValue))
                            {
                                throw new LuaException($"Invalid data type for '{initInstance[0]}.{key}' (expected {type.Name}, got {kv.Value.WrappedClrType()})");
                            }

                            if (isActorReference)
                            {
                                clrValue = type == typeof(string) ? new ActorInitActorReference((string)clrValue) : new ActorInitActorReference((Actor)clrValue);
                            }

                            initValues[key] = clrValue;
                        }
                }

                compositeInit.Initialize(initValues);
                return(init);
            }

            // HACK: Backward compatibility for legacy int facings
            if (init is FacingInit facingInit)
            {
                if (value.TryGetClrValue(out int facing))
                {
                    facingInit.Initialize(WAngle.FromFacing(facing));
                    TextNotificationsManager.Debug("Initializing Facing with integers is deprecated. Use Angle instead.");
                    return(facingInit);
                }
            }

            var initializers = initType.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
                               .Where(m => m.Name == "Initialize" && m.GetParameters().Length == 1);

            foreach (var initializer in initializers)
            {
                var parameterType = initializer.GetParameters().First().ParameterType;
                var valueType     = parameterType.IsEnum ? Enum.GetUnderlyingType(parameterType) : parameterType;

                // Try and coerce the table value to the required type
                if (!value.TryGetClrValue(valueType, out var clrValue))
                {
                    continue;
                }

                initializer.Invoke(init, new[] { clrValue });

                return(init);
            }

            var types = initializers.Select(y => y.GetParameters()[0].ParameterType.Name).JoinWith(", ");

            throw new LuaException($"Invalid data type for '{initInstance[0]}' (expected one of {types})");
        }
示例#16
0
 void Deprecated()
 {
     TextNotificationsManager.Debug("The Facing table is deprecated. Use Angle instead.");
 }