예제 #1
0
        private void ExampleMod_Event_GameEvent(GameEventData obj)
        {
            log("*****************OMG it's a game event!!!");
            var eventMessage = new IdMsgPrio
            {
                msg = $@"A game event occured, name:{obj.Name}, type:{obj.Type}, eventType:{obj.EventType}"
            };

            this.Request_InGameMessage_AllPlayers(eventMessage);
        }
예제 #2
0
        public void MessagePlayer(int id, string message)
        {
            var outMsg = new IdMsgPrio()
            {
                id  = id,
                msg = message
            };

            Request_InGameMessage_SinglePlayer(outMsg);
        }
예제 #3
0
        public override void Initialize(ModGameAPI dediAPI)
        {
            this.Update_Received   += ExampleMod_Update_Received;
            this.Event_ChatMessage += ExampleMod_Event_HandleLottoChatMessage;
            this.Event_GameEvent   += ExampleMod_Event_GameEvent;
            this.Event_Statistics  += PlayerDied_Event_Statistics;
            this.ChatCommands.Add(new ChatCommand(@"/repeat (?<repeat>\S+)", ChatCommand_TestMessage));
            this.ChatCommands.Add(new ChatCommand(@"!loudly (?<yellthis>.+)", (data, args) => {
                var msg = new IdMsgPrio()
                {
                    id  = data.playerId,
                    msg = $"{args["yellthis"].ToUpper()}!!!!!"
                };
                this.Request_InGameMessage_SinglePlayer(msg);
            }));

            this.ChatCommands.Add(new ChatCommand(@"/explosion", (data, __) => {
                var dialogData = new DialogBoxData()
                {
                    Id            = data.playerId,
                    MsgText       = "BOOM!",
                    PosButtonText = "yes",
                    NegButtonText = "No"
                };
                this.Request_ShowDialog_SinglePlayer(dialogData, (result) => {
                    var resultInterpreted = result.Value == 0 ? "YES": "NO";
                    this.Request_InGameMessage_SinglePlayer(resultInterpreted.ToIdMsgPrio(data.playerId));
                });
            }, "blows it up", PermissionType.Moderator));



            this.ChatCommands.Add(new ChatCommand(@"/help", (data, __) => {
                this.Request_Player_Info(data.playerId.ToId(), (info) =>
                {
                    var playerPermissionLevel = (PermissionType)info.permission;
                    var header = $"Commands available to {info.playerName}; permission level {playerPermissionLevel}\n";

                    var lines = this.GetChatCommandsForPermissionLevel(playerPermissionLevel)
                                .Select(x => x.ToString())
                                .OrderBy(x => x.Length).ToList();

                    lines.Insert(0, header);


                    var dialogData = new DialogBoxData()
                    {
                        Id      = data.playerId,
                        MsgText = String.Join("\n", lines.ToArray())
                    };

                    Request_ShowDialog_SinglePlayer(dialogData);
                });
            }));
        }
예제 #4
0
        private void ChatCommand_TestMessage(ChatInfo data, Dictionary <string, string> args)
        {
            var repeating = args["repeat"];
            var msg       = new IdMsgPrio()
            {
                id  = data.playerId,
                msg = $"{repeating} {repeating} {repeating}!"
            };

            this.Request_InGameMessage_SinglePlayer(msg);
        }
예제 #5
0
        private void ExampleMod_Update_Received(ulong tick)
        {
            if (tick % 10000 == 0)
            {
                var param = new IdMsgPrio()
                {
                    msg = $"game tick is now {tick}, an auspicious number"
                };

                this.Request_InGameMessage_AllPlayers(param);
            }
        }
        private void getHelp(ChatInfo data, PString subcommand)
        {
            var msg = new IdMsgPrio()
            {
                msg  = helpMessage,
                id   = data.playerId,
                prio = 1
            };
            var cmd = new APICmd(CmdId.Request_ShowDialog_SinglePlayer, msg);

            broker.ExecuteCommand(cmd);
        }
        private Account incrementPointOnActiveFaction(Account factionAccount)
        {
            var key = int.Parse(factionAccount.id);

            log(() => $"*** incrementing faction points for {key}");
            CrewInfo info;

            log(() => $"current crews: {Serializer.Serialize(CrewInfoTracker)}");
            info = CrewInfoTracker.TryGetValue(key, out info) ? info : new CrewInfo();


            var points = (info.crewMembers.Keys.Count + info.researchTeam.members.Count + (info.researchTeam.leader != null?1:0));

            log(() => $"*** points: { points}");
            log(() => $"*** members: { info.crewMembers.Keys.Count}");
            log(() => $"*** cluster size: { info.researchTeam.members.Count}");

            factionAccount.balances[ResourceType.Points] += points;
            var message = generateFactionPointMessage(info, points);

            if (info.crewMembers.Keys.Count == 0)
            {
                log(() => $"crew has no active members {Serializer.Serialize(info)}");
                return(factionAccount);
            }

            var singlePlayerCrew = info.crewMembers.Keys.Count == 1;

            var singlePlayerId = info.crewMembers.Values.First().entityId;
            var factionId      = int.Parse(factionAccount.id);



            var msg = new IdMsgPrio()
            {
                id   = singlePlayerCrew ? singlePlayerId: factionId,
                msg  = message,
                prio = 1
            };

            log(() => $"factionMessage: {message}");
            log(() => $"crewInfo: {Serializer.Serialize(info)}");
            var cmdId = singlePlayerCrew ? CmdId.Request_InGameMessage_SinglePlayer : CmdId.Request_InGameMessage_Faction;
            var cmd   = new APICmd(cmdId, msg);

            broker.ExecuteCommand(cmd);
            info.researchTeam    = new ResearchTeam();
            CrewInfoTracker[key] = info;
            return(factionAccount);
        }
예제 #8
0
        private void ExampleMod_Event_HandleLottoChatMessage(ChatInfo obj)
        {
            log("lotto check");
            if (obj.msg != "lottery")
            {
                return;
            }

            this.Request_Player_List(list =>
            {
                var index      = rnd.Next() % list.list.Count;
                var selectedId = list.list[index];

                var msgParam = new IdMsgPrio()
                {
                    id  = selectedId,
                    msg = $"Congratulations!, You Won!"
                };

                var rewardParam = new ItemExchangeInfo()
                {
                    id         = selectedId,
                    buttonText = "ok",
                    title      = "test",
                    desc       = "testdesc",
                    items      = new ItemStack[] {
                        new ItemStack()
                        {
                            id    = 256,
                            count = 1
                        }
                    }
                };

                this.Request_Player_ItemExchange(rewardParam, result =>
                {
                    log($"itemexchange result count {result.items.Count()}");
                    if (result.items.Count() == 0)
                    {
                        return;
                    }
                    var tyParam = new IdMsgPrio()
                    {
                        id  = selectedId,
                        msg = $"Thanks for the gift!"
                    };
                    this.Request_InGameMessage_SinglePlayer(tyParam);
                }, x => log($"itemexchange error: {x.errorType.ToString()}"));
            });
        }
예제 #9
0
        private async void ExampleMod_Event_HandleLottoChatMessage(MessageData obj)
        {
            Logger.log("lotto check");
            if (obj.Text != "lottery")
            {
                return;
            }

            var list = await Broker.Request_Player_List();

            var index      = RNG.Next() % list.list.Count;
            var selectedId = list.list[index];

            var msgParam = new IdMsgPrio()
            {
                id  = selectedId,
                msg = $"Congratulations!, You Won!"
            };

            var rewardParam = new ItemExchangeInfo()
            {
                id         = selectedId,
                buttonText = "ok",
                title      = "test",
                desc       = "testdesc",
                items      = new ItemStack[]
                {
                    new ItemStack()
                    {
                        id    = 256,
                        count = 1
                    }
                }
            };

            try
            {
                var result = await Broker.Request_Player_ItemExchange(rewardParam);

                if (result.items.Any())
                {
                    return;
                }

                MessagePlayer(selectedId, $"Thanks for the gift!");
            } catch (EmpyrionAPIException ex)
            {
                Logger.log($"itemexchange error: {ex.info.ToString()}");
            }
        }
예제 #10
0
        private static void showTable(int playerId, string message = "")
        {
            var table = modManager.getModTable();

            var outMsg = message != "" ? $"{message}\n***\n{table}" : table;

            var msg = new IdMsgPrio()
            {
                id  = playerId,
                msg = outMsg,
            };

            Broker.api.Console_Write("list!!");
            new GenericAPICommand(CmdId.Request_ShowDialog_SinglePlayer, msg).Execute();
        }
        private void withdrawUpgradePoints(ChatInfo data, PString subcommand)
        {
            int value;

            value = int.TryParse(subcommand.pstr, out value) ? value : -1;
            if (value < 0)
            {
                return;
            }
            log(() => $"*** beginning transfer of {value}");
            this.transferBalance(data.playerId, value, TransactionType.UpgradePoints, x => {
                log(() => "***** transfer response");

                string balanceMessage;
                string factionMessage;
                if (x.succeeded)
                {
                    balanceMessage = $"withdrawal successful\nyour crew has a balance of {x.crewBalance} points;\nyour personal balance is {x.playerBalance} points";
                    factionMessage = $"{x.playerName} has withdrawn {value} points from the crew bank";

                    var facmsg = new IdMsgPrio()
                    {
                        id   = x.crewAccount,
                        msg  = factionMessage,
                        prio = (byte)(x.succeeded ? 1 : 0)
                    };

                    var cmd = new APICmd(CmdId.Request_InGameMessage_Faction, facmsg);
                    broker.ExecuteCommand(cmd);
                }
                else
                {
                    balanceMessage = $"withdrawal failed: {x.reason}";
                }

                var msg = new IdMsgPrio()
                {
                    id   = data.playerId,
                    msg  = balanceMessage,
                    prio = (byte)(x.succeeded ? 1:0)
                };
                var outmsg = new APICmd(CmdId.Request_InGameMessage_SinglePlayer, msg);
                broker.ExecuteCommand(outmsg);
            });
        }
예제 #12
0
        public static void Request_InGameMessage_Faction(IdMsgPrio arg, Action callback = null, Action <ErrorInfo> onError = null)
        {
            Action <CmdId, object> wiredCallback = null;

            if (callback != null)
            {
                wiredCallback = (_, val) => callback();
            }

            var apiCmd = new GenericAPICommand(
                CmdId.Request_InGameMessage_Faction,
                arg,
                wiredCallback,
                onError ?? noOpErrorHandler
                );

            Broker.Execute(apiCmd);
        }
        private void convertCredits(ChatInfo data, PString subcommand)
        {
            int value;

            value = int.TryParse(subcommand.pstr, out value) ? value : -1;
            if (value < 0)
            {
                return;
            }
            var result = convertPointsToCredits(data.playerId, value);
            var msg    = new IdMsgPrio()
            {
                id   = data.playerId,
                msg  = $"you converted {result.amountRequested} points to credits",
                prio = 1
            };
            var outmsg = new APICmd(CmdId.Request_InGameMessage_SinglePlayer, msg);

            broker.ExecuteCommand(outmsg);
        }
예제 #14
0
        private void PlayerDied_Event_Statistics(StatisticsParam obj)
        {
            log("***************event statistics!!!");
            var container = StatisticsContainer.FromStatisticsParam(obj);

            switch (container)
            {
            case PlayerDiedStatistics deathStats:
                var msg = new IdMsgPrio
                {
                    msg = $"Player {deathStats.PlayerId.id} was killed by {deathStats.KillerId.id}"
                };
                log(msg.msg);
                this.Request_InGameMessage_AllPlayers(msg);
                break;

            default:
                break;
            }
        }
        private async void PlayerDied_Event_Statistics(StatisticsParam obj)
        {
            //Log("***************event statistics!!!");
            var container = StatisticsContainer.FromStatisticsParam(obj);

            switch (container)
            {
            case PlayerDiedStatistics deathStats:
                var msg = new IdMsgPrio
                {
                    msg = $"Player {deathStats.PlayerId.id} was killed by {deathStats.KillerId.id}"
                };
                broker.Log(msg.msg);
                await broker.SendRequestAsync(CmdId.Request_InGameMessage_AllPlayers, msg);

                break;

            default:
                break;
            }
        }
        private void checkCrewBalance(ChatInfo data, PString subcommand)
        {
            var playerId = new Id(data.playerId);
            var cmd      = new APICmd(CmdId.Request_Player_Info, playerId);

            broker.ExecuteCommand <PlayerInfo>(cmd, (cmdId, playerInfo) =>
            {
                var crewAccount     = SafeGetAccount(AccountType.Crew, playerInfo.factionId, playerInfo);
                var crewBalance     = crewAccount.balances[ResourceType.Points];
                var personalAccount = SafeGetAccount(playerInfo);
                var personalBalance = personalAccount.balances[ResourceType.Points];
                var balanceMessage  = $"your crew has a balance of {crewBalance} points;\nyour personal balance is {personalBalance} points";
                var msg             = new IdMsgPrio()
                {
                    id   = playerInfo.entityId,
                    msg  = balanceMessage,
                    prio = 1
                };
                var outmsg = new APICmd(CmdId.Request_InGameMessage_SinglePlayer, msg);
                broker.ExecuteCommand(outmsg);
            });
        }
예제 #17
0
 public static Task <object> Request_InGameMessage_Faction(IdMsgPrio param)
 {
     return(Broker.CreateCommandWithArgAndReturn <IdMsgPrio, object>(CmdId.Request_InGameMessage_Faction, param));
 }
예제 #18
0
 public async Task <bool> Request_InGameMessage_Faction(IdMsgPrio arg, CancellationToken ct)
 {
     return(await Broker.SendRequestAsync(CmdId.Request_InGameMessage_Faction, arg, ct));
 }
예제 #19
0
 public async Task <bool> Request_InGameMessage_AllPlayers(IdMsgPrio arg)
 {
     return(await Broker.SendRequestAsync(CmdId.Request_InGameMessage_AllPlayers, arg));
 }
예제 #20
0
 public static Task <object> Request_InGameMessage_Faction(IdMsgPrio param, Action callback, Action <ErrorInfo> onError = null)
 {
     return(Broker.CreateCommandWithArgAndReturn <IdMsgPrio, object>(CmdId.Request_InGameMessage_Faction, param, callback, onError));
 }
예제 #21
0
 /// <summary>
 /// Sends an in-game message to a single player. This is not a reference to single-player mode but instead means that only one player will receive the message.
 /// The in-game message is a box that appears in the upper-right of the screen, much like a base attack message. Id is ignored.
 /// </summary>
 /// <param name="data">Parameters that define the look and content of the message.</param>
 public void RequestInGameMessageAllPlayers(IdMsgPrio data)
 {
     // No callback for this request.
     EmpyrionExtension.LegacyApi.Game_Request(CmdId.Request_InGameMessage_AllPlayers, SequenceNumber, data);
 }
예제 #22
0
 public void Request_InGameMessage_Faction(IdMsgPrio arg, Action callback = null, Action <ErrorInfo> onError = null)
 {
     Broker.Request_InGameMessage_Faction(arg, callback, onError);
 }