Example #1
0
 public static void Add(this NPCInventory inventory, IEnumerable <StoredItem> items)
 {
     foreach (var item in items)
     {
         inventory.Add(item);
     }
 }
 public virtual ITrackableBlock InitializeOnAdd(Vector3Int position, ushort type, Players.Player player)
 {
     blockType      = type;
     blockInventory = new NPCInventory(10000000f);
     positionNPC    = GetPositionNPC(position);
     InitializeJob(player, position, 0);
     return(this);
 }
 static void AddResults(NPCInventory inv)
 {
     inv.Add(BuiltinBlocks.LogTemperate, 3);
     inv.Add(BuiltinBlocks.LeavesTemperate, 9);
     inv.Add(BuiltinBlocks.Sapling);
     if (Random.NextDouble() > 0.25)
     {
         inv.Add(BuiltinBlocks.Sapling);
     }
 }
Example #4
0
    // Use this for initialization
    void Start()
    {
        npcinventory = NPCInventory.instance;

        // Add our UpdateUI method to the inventory callback stack
        // so that when the inventory is updated, this UpdateUI gets called.
        npcinventory.OnNPCItemChangedCallback += UpdateUI;

        slots = itemsParent.GetComponentsInChildren <NPCInventorySlot>();
    }
 public static void Add(this NPCInventory inventory, IEnumerable <InventoryItem> items, int multiplier)
 {
     if (items != null)
     {
         foreach (var item in items)
         {
             inventory.Add(item * multiplier);
         }
     }
 }
Example #6
0
    private void Awake()
    {
        if (instance != null)
        {
            Debug.LogWarning("More than one instance of NPCInventory found!");
            return;
        }

        instance = this;
    }
        public override ITrackableBlock InitializeFromJSON(Players.Player player, JSONNode node)
        {
            blockInventory = new NPCInventory(node["inventory"]);
            storedFuel     = node.GetAs <float>("storedFuel");
            blockType      = ItemTypes.IndexLookup.GetIndex(node.GetAs <string>("type"));
            Vector3Int position = (Vector3Int)node["position"];

            positionNPC = GetPositionNPC(position);
            InitializeJob(player, position, node.GetAs <int>("npcID"));
            return(this);
        }
Example #8
0
        public ITrackableBlock InitializeOnAdd(Vector3Int position, ushort type, Players.Player player)
        {
            BlockInventory = new NPCInventory(10000000f);
            InitializeJob(player, position, 0);
            Fullname = ItemTypes.IndexLookup.GetName(type);
            string blueprintTypename = Fullname.Substring(0, Fullname.Length - 2);

            ManagerBlueprints.Blueprints.TryGetValue(blueprintTypename, out List <BlueprintTodoBlock> blocks);
            Todoblocks = new List <BlueprintTodoBlock> (blocks);
            Todoblocks.Reverse();
            return(this);
        }
Example #9
0
        public override ITrackableBlock InitializeFromJSON(Players.Player player, JSONNode node)
        {
            BlockInventory  = new NPCInventory(10000000f, node ["inventory"]);
            ShouldTakeItems = false;
            node.TryGetAs("shouldTakeItems", out ShouldTakeItems);
            Fullname = node.GetAs <string> ("fullname");
            JSONNode jsonTodos = node ["todoblocks"];

            Todoblocks = new List <BlueprintTodoBlock> ();
            foreach (JSONNode jsonBlock in jsonTodos.LoopArray())
            {
                Todoblocks.Add(new BlueprintTodoBlock(jsonBlock));
            }
            InitializeJob(player, (Vector3Int)node ["position"], node.GetAs <int> ("npcID"));
            return(this);
        }
Example #10
0
 public override ITrackableBlock InitializeFromJSON(Players.Player player, JSONNode node)
 {
     blockInventory = new NPCInventory(10000000f, node["inventory"]);
     InitializeJob(player, (Vector3Int)node["position"], node.GetAs <int>("npcID"));
     return(this);
 }
        public override void OnNPCAtJob(IAreaJob rawJob, ref Vector3Int positionSub, ref NPCBase.NPCState state, ref bool shouldDumpInventory)
        {
            BerryFarmerJob job = (BerryFarmerJob)rawJob;

            state.JobIsDone = true;
            if (positionSub.IsValid)
            {
                ushort type;
                if (job.placingMissingBush)
                {
                    if (job.UsedNPC.Colony.UsedStockpile.TryRemove(BuiltinBlocks.BerryBush))
                    {
                        job.placingMissingBush = false;
                        ServerManager.TryChangeBlock(job.bushLocation, BuiltinBlocks.BerryBush, rawJob.Owner, ServerManager.SetBlockFlags.DefaultAudio);
                        state.SetCooldown(2.0);
                    }
                    else
                    {
                        state.SetIndicator(new Shared.IndicatorState(Random.NextFloat(8f, 14f), BuiltinBlocks.BerryBush, true, false));
                    }
                }
                else if (job.removingOldBush)
                {
                    if (ServerManager.TryChangeBlock(job.bushLocation, 0, rawJob.Owner, ServerManager.SetBlockFlags.DefaultAudio))
                    {
                        job.UsedNPC.Colony.UsedStockpile.Add(BuiltinBlocks.BerryBush);
                        job.removingOldBush = false;
                    }
                    state.SetCooldown(2.0);
                }
                else if (World.TryGetTypeAt(positionSub, out type))
                {
                    if (type == 0)
                    {
                        job.checkMissingBushes = true;
                        state.SetCooldown(1.0, 4.0);
                    }
                    else if (type == BuiltinBlocks.BerryBush)
                    {
                        state.SetIndicator(new Shared.IndicatorState(8.5f, BuiltinBlocks.Berry));
                        NPCInventory inv = job.UsedNPC.Inventory;
                        inv.Add(BuiltinBlocks.Berry);
                        if (Random.Next(0, 10) >= 9)
                        {
                            inv.Add(BuiltinBlocks.BerryBush);
                        }
                    }
                    else
                    {
                        state.SetIndicator(new Shared.IndicatorState(Random.NextFloat(8f, 14f), BuiltinBlocks.ErrorMissing));
                    }
                }
                else
                {
                    state.SetCooldown(Random.NextFloat(3f, 6f));
                }
                positionSub = Vector3Int.invalidPos;
            }
            else
            {
                state.SetCooldown(10.0);
            }
        }
 public ITrackableBlock InitializeOnAdd(Vector3Int position, ushort type, Players.Player player)
 {
     blockInventory = new NPCInventory(10000000f);
     InitializeJob(player, position, 0);
     return(this);
 }