Ejemplo n.º 1
0
        public void Connect(IPAddress publicIP, ushort port)
        {
            if (IsServer)
            {
                throw new InvalidOperationException("This instance of CoreNetworkSystem is a server!  It cannot be told to connect to a remote client; the client must be told to connect here.");
            }

            ModSystem.Connect(publicIP, port);
        }
Ejemplo n.º 2
0
        public async Task Run(string[] args)
        {
            // Init vars
            Cts = new CancellationTokenSource();
            Ct  = Cts.Token;

            _modSystem = new ModSystem();
            _logger    = new LogManager("discord-", "-tmodloader");

            // Setup objects
            _client = new DiscordSocketClient(new DiscordSocketConfig()
            {
                AlwaysDownloadUsers = true,
                LogLevel            = LogSeverity.Debug,
                MessageCacheSize    = 500
            });

            // Setup event handlers
            _client.Log             += ClientLog;
            _client.JoinedGuild     += ClientJoinGuild;
            _client.Ready           += ClientReady;
            _client.LatencyUpdated  += ClientLatencyUpdated;
            _client.ReactionAdded   += ClientReactionAdded;
            _client.ReactionRemoved += ClientReactionRemoved;
            // awaitable login
            await Login();

            var map = new DependencyMap();

            map.Add(_client);
            map.Add(_modSystem);
            map.Add(_logger);

            Handler = new CommandHandler();
            await Handler.Install(map);

            Console.Title = "The Guide - " + ConfigManager.Properties.Version;

            // Block program until it's closed or task is canceled
            await Task.Delay(-1, Ct);
        }
Ejemplo n.º 3
0
 public void Test1()
 {
     int[] lst = new int[] { 8, 7, 5, 3 };
     Assert.AreEqual("-3--5--2--1-", ModSystem.fromNb2Str(187, lst));
 }
Ejemplo n.º 4
0
 public void Test4()
 {
     int[] lst = new int[] { 2, 3 };
     Assert.AreEqual("Not applicable", ModSystem.fromNb2Str(7, lst));
 }
Ejemplo n.º 5
0
 public void Test2()
 {
     int[] lst = new int[] { 2, 3, 5 };
     Assert.AreEqual("-1--2--1-", ModSystem.fromNb2Str(11, lst));
 }
Ejemplo n.º 6
0
 public static void RegisterTool(ModSystem mod)
 {
     ((WorldEdit.WorldEdit)mod).RegisterTool("TreeGen", typeof(TreeGenTool));
 }
Ejemplo n.º 7
0
        public static void Initialize(ICoreAPI api_, ModSystem mod)
        {
            api = api_;
            if (api.Side == EnumAppSide.Server)
            {
                buffTypes.Clear();
                activeBuffsByEntityAndBuffId.Clear();
                inactiveBuffsByPlayerUid.Clear();

                var sapi = api as ICoreServerAPI;
                sapi.Event.SaveGameLoaded += () => {
                    var data = sapi.WorldManager.SaveGame.GetData($"{mod.Mod.Info.ModID}:BuffStuff");
                    if (data != null)
                    {
                        inactiveBuffsByPlayerUid = SerializerUtil.Deserialize <Dictionary <string, List <SerializedBuff> > >(data);
                    }
                };
                sapi.Event.GameWorldSave += () => {
                    var activeAndInactiveBuffsByPlayerUid = new Dictionary <string, List <SerializedBuff> >(inactiveBuffsByPlayerUid); // shallow clone dictionary
                    foreach (var entityActiveBuffsByBuffIdPair in activeBuffsByEntityAndBuffId)                                        // add active buffs too!
                    {
                        var playerEntity = entityActiveBuffsByBuffIdPair.Key as EntityPlayer;
                        if (playerEntity != null)
                        {
                            activeAndInactiveBuffsByPlayerUid[playerEntity.PlayerUID] = entityActiveBuffsByBuffIdPair.Value.Select(pair => serializeBuff(pair.Value)).ToList();
                        }
                    }
                    sapi.WorldManager.SaveGame.StoreData($"{mod.Mod.Info.ModID}:BuffStuff", SerializerUtil.Serialize <Dictionary <string, List <SerializedBuff> > >(activeAndInactiveBuffsByPlayerUid));
                };
                sapi.Event.PlayerNowPlaying += (serverPlayer) => {
                    var playerUid = (serverPlayer.Entity as EntityPlayer).PlayerUID;
                    if (inactiveBuffsByPlayerUid.TryGetValue(playerUid, out var inactiveBuffs))
                    {
                        var now = Now;
                        activeBuffsByEntityAndBuffId[serverPlayer.Entity] = inactiveBuffs.Select(serializedBuff => deserializeBuff(serializedBuff, serverPlayer.Entity)).Where((buff) => buff != null).ToDictionary(buff => buffTypeToIds[buff.GetType()], buff => buff);
                        inactiveBuffsByPlayerUid.Remove(playerUid);
                        foreach (var buffIdAndBuffPair in activeBuffsByEntityAndBuffId[serverPlayer.Entity])
                        {
                            buffIdAndBuffPair.Value.OnJoin();
                        }
                    }
                };
                sapi.Event.PlayerLeave += (serverPlayer) => {
                    var playerUid = (serverPlayer.Entity as EntityPlayer).PlayerUID;
                    if (activeBuffsByEntityAndBuffId.TryGetValue(serverPlayer.Entity, out var activeBuffsByBuffId))
                    {
                        foreach (var activeBuffsByBuffIdPair in activeBuffsByBuffId)
                        {
                            activeBuffsByBuffIdPair.Value.OnLeave();
                        }
                        inactiveBuffsByPlayerUid[playerUid] = activeBuffsByBuffId.Select(pair => serializeBuff(pair.Value)).ToList();
                        // activeBuffs.ToDictionary(pair => pair.Key, pair => pair.Value - now); // convert remaining time to future timestamp
                        activeBuffsByEntityAndBuffId.Remove(serverPlayer.Entity);
                    }
                };
                sapi.Event.OnEntityDespawn += (Entity entity, EntityDespawnReason reason) => {
                    activeBuffsByEntityAndBuffId.Remove(entity);
                };
                sapi.Event.PlayerDeath += (serverPlayer, damageSource) => {
                    if (activeBuffsByEntityAndBuffId.TryGetValue(serverPlayer.Entity, out var activeBuffsByBuffId))
                    {
                        foreach (var activeBuffsByBuffIdPair in activeBuffsByBuffId)
                        {
                            activeBuffsByBuffIdPair.Value.OnDeath();
                        }
                    }
                    activeBuffsByEntityAndBuffId.Remove(serverPlayer.Entity);
                };
                sapi.World.RegisterGameTickListener((float dt) => {
                    var now = Now;
                    foreach (var entity in activeBuffsByEntityAndBuffId.Keys.ToArray())
                    {
                        var activeBuffsByBuffId = activeBuffsByEntityAndBuffId[entity];
                        foreach (var buff in activeBuffsByBuffId.Values.ToArray())
                        {
                            if (buff.ExpireTimestampInDays < now || buff.TickCounter >= buff.ExpireTick)
                            {
                                buff.OnExpire();
                                RemoveBuff(entity, buff);
                                continue;
                            }
                            buff.TickCounter += 1;
                            buff.OnTick();
                            if (buff.ExpireTimestampInDays < now || buff.TickCounter >= buff.ExpireTick)
                            {
                                buff.OnExpire();
                                RemoveBuff(entity, buff);
                            }
                        }
                    }
                }, TICK_MILLISECONDS);
            }
            isInitialized = true;
        }
Ejemplo n.º 8
0
 public static void RegisterTool(ModSystem mod)
 {
     ((WorldEdit)mod).RegisterTool("HeightmapImporter", typeof(HeightmapImporterTool));
 }