Ejemplo n.º 1
0
 public override void InitNew()
 {
     base.InitNew();
     Name  = "NPC-Farmer";
     Build = true;
     KingdomsTracker.SendKingdomNotification($"Placed a {KingdomType} of size {Size} at {Origin}");
 }
Ejemplo n.º 2
0
        public virtual void InitFromJson(JSONNode jsonNode)
        {
            if (!jsonNode.TryGetAs("NpcID", out NpcID))
            {
                NpcID = KingdomsTracker.GetNextNpcID();
            }
            string name;

            if (jsonNode.TryGetAs("Name", out name))
            {
                Name = name;
            }
            JSONNode jsonOrigin;

            if (jsonNode.TryGetAs("Origin", out jsonOrigin))
            {
                Origin = (Vector3Int)jsonOrigin;
            }
            string networkID;

            if (jsonNode.TryGetAs("NetworkID", out networkID))
            {
                NetworkID = NetworkID.Parse(networkID);
            }
            else
            {
                NetworkID = CreateFakeNetworkID(NpcID);
            }
            FinishInitialization();
        }
Ejemplo n.º 3
0
 public virtual void FinishInitialization()
 {
     KingdomsTracker.RegisterKingdom(this);
     ThreadManager.InvokeOnMainThread(delegate {
         var player  = Players.GetPlayer(NetworkID);
         player.Name = Name;
     });
     LootSpawner.Start(NetworkID);
 }
Ejemplo n.º 4
0
 public void Kill()
 {
     Dead = true;
     LootSpawner.Kill();
     KingdomsTracker.UnregisterKingdom(this);
     ThreadManager.InvokeOnMainThread(delegate {
         var followers = new List <NPCBase> (Colony.Get(Players.GetPlayer(NetworkID)).Followers);
         followers.ForEach(follower => follower.OnDeath());
     });
 }
Ejemplo n.º 5
0
        void UpdateLoot()
        {
            var invocationDelay = Properties.MinRespawnDelayMinutes + Pipliz.Random.Next(Properties.MaxRespawnDelayMinutes - Properties.MinRespawnDelayMinutes);

            ThreadManager.InvokeOnMainThread(delegate {
                try {
                    if (Dead)
                    {
                        return;
                    }
                    var lootType = ItemTypes.IndexLookup.GetIndex(Lootbox.ITEMKEY);
                    foreach (var oldPlacedLoot in new List <Vector3Int> (PlacedLoot))
                    {
                        ushort actualType;
                        if (World.TryGetTypeAt(oldPlacedLoot, out actualType) && actualType != lootType)
                        {
                            PlacedLoot.Remove(oldPlacedLoot);
                        }
                    }
                    int spawnCount      = Properties.MinCount + Pipliz.Random.Next(Properties.MaxCount - Properties.MinCount - PlacedLoot.Count);
                    var player          = Players.GetPlayer(NetworkID);
                    var currentSpotList = new List <Vector3Int> (PossibleLootSpots);
                    for (int c = 0; c < spawnCount && currentSpotList.Count > 0;)
                    {
                        var spot     = Pipliz.Random.Next(currentSpotList.Count);
                        var position = currentSpotList [spot];
                        currentSpotList.RemoveAt(spot);
                        ushort actualType;
                        if (World.TryGetTypeAt(position, out actualType) && actualType == BuiltinBlocks.Air)
                        {
                            PlacedLoot.Add(position);
                            BlockPlacementHelper.PlaceBlock(position, lootType, player);
                            c++;
                            KingdomsTracker.SendLootboxNotification($"Unclaimed lootbox at {position}");
                        }
                    }
                } catch (Exception exception) {
                    Log.WriteError($"Exception while spawning loot; {exception.Message}");
                }
                UpdateLoot();
            }, invocationDelay * 60);
        }
 public bool TryDoCommand(Players.Player causedBy, string chattext)
 {
     try {
         if (PermissionsManager.CheckAndWarnPermission(causedBy, KingdomsModEntries.MOD_PREFIX + $"kill{KingdomType}"))
         {
             NpcKingdom closestFarm;
             if (chattext.Equals($"/kill{KingdomType} all"))
             {
                 KingdomsTracker.GetAllByType(KingdomType).ForEach(kingdom => kingdom.Kill());
                 KingdomsTracker.SendKingdomNotification($"killed all {KingdomType}");
             }
             else if (KingdomsTracker.TryGetClosest(KingdomType, causedBy.VoxelPosition, out closestFarm))
             {
                 closestFarm.Kill();
                 KingdomsTracker.SendKingdomNotification($"Killed {KingdomType} at {closestFarm.Origin}");
             }
         }
     } catch (Exception exception) {
         Log.WriteError($"Exception while parsing command; {exception.Message} - {exception.StackTrace}");
     }
     return(true);
 }
Ejemplo n.º 7
0
 protected override void Update(Players.Player player)
 {
     if (Build)
     {
         Build = false;
         var builder = new NpcFarmBuilder(player, Origin, Size);
         builder.Build();
         LootSpawner.SetPossibleLootSpots(builder.LootSpots);
     }
     else if (BedBlockTracker.GetCount(player) < 1)
     {
         KingdomsTracker.SendKingdomNotification($"Farm at {Origin} is dead! Lost all beds");
         Kill();
     }
     else
     {
         var stockpile = Stockpile.GetStockPile(player);
         var colony    = Colony.Get(player);
         CheckItemAmount(stockpile, BuiltinBlocks.Bread, 5000);
         CheckFollower(player, colony);
         CheckItemAmount(stockpile, BuiltinBlocks.WheatStage1, 100);
     }
 }
Ejemplo n.º 8
0
 public bool TryDoCommand(Players.Player causedBy, string chattext)
 {
     try {
         if (!Permissions.PermissionsManager.CheckAndWarnPermission(causedBy, KingdomsModEntries.MOD_PREFIX + "listfarms"))
         {
             return(true);
         }
         var m = Regex.Match(chattext, @"/kingdomlist( (?<kingdomType>.+))?");
         if (!m.Success)
         {
             Chat.Send(causedBy, "Command didn't match, use /kingdomlist [kingdomType]");
             return(true);
         }
         var kingdomType = m.Groups ["kingdomType"].Value;
         List <NpcKingdom> kingdoms;
         if (kingdomType.Length < 1 || "all".Equals(kingdomType))
         {
             kingdoms = KingdomsTracker.GetAll();
         }
         else
         {
             kingdoms = KingdomsTracker.GetAllByType(kingdomType);
         }
         var msg = string.Join("\n", kingdoms.Select(f => $"{kingdomType} at {f.Origin}").ToArray());
         if (msg.Length < 1)
         {
             Chat.Send(causedBy, $"No '{kingdomType}' kingdoms found");
         }
         else
         {
             Chat.Send(causedBy, msg);
         }
     } catch (Exception exception) {
         Log.WriteError($"Exception while parsing command; {exception.Message} - {exception.StackTrace}");
     }
     return(true);
 }
Ejemplo n.º 9
0
 public virtual void InitNew()
 {
     NpcID     = KingdomsTracker.GetNextNpcID();
     NetworkID = CreateFakeNetworkID(NpcID);
     FinishInitialization();
 }