private void SpawnNpc(NPCRole npcRoleEnum, Coordinates position)
        {
            switch (npcRoleEnum)
            {
            case NPCRole.LUMBERJACK:
                SpawnLumberjack(position);
                break;

            case NPCRole.WIZARD:
                SpawnWizard(position);
                break;
            }
        }
Beispiel #2
0
        /// <summary>
        /// 生成NPC角色数据
        /// </summary>
        /// <param name="myNpc"></param>
        /// <returns></returns>
        public static Byte[] GenerateNpcRoleBufferData(NPC myNpc)
        {
            SystemXmlItem systemNPC = null;

            if (!GameManager.SystemNPCsMgr.SystemXmlItemDict.TryGetValue(myNpc.NpcID, out systemNPC))
            {
                return(null);
            }

            NPCRole npcRole = new NPCRole();

            npcRole.NpcID   = myNpc.NpcID;
            npcRole.PosX    = (int)myNpc.CurrentPos.X;
            npcRole.PosY    = (int)myNpc.CurrentPos.Y;
            npcRole.MapCode = myNpc.MapCode;
            npcRole.Dir     = (int)myNpc.CurrentDir;

            npcRole.RoleString = systemNPC.XMLNode.ToString();

            return(DataHelper.ObjectToBytes <NPCRole>(npcRole));
        }
Beispiel #3
0
        /// <summary>
        /// This is for initializing every necessary variables and aspects for trading
        /// </summary>
        public void StartTrade(NPCRole npcRoleLocal, PlayerStats playerCharLocal, BaseCharacter npcCharLocal, InventoryObject playerInvLocal)
        {
            if (!npcRole.canTrade || _isStartedTrade)
            {
                return;
            }
            OpenTradeWindow();
            HideCursor.Show();
            Time.timeScale = 0f;

            _isStartedTrade = true;

            npcRole     = npcRoleLocal;
            playerStats = playerCharLocal;
            npcChar     = npcCharLocal;
            playerInv   = playerInvLocal;

            // Limits size of the list
            _itemCellListNpc    = new List <GameObject>(maxCellSize);
            _itemCellListPlayer = new List <GameObject>(maxCellSize);

            // Get a list of item cell objects
            _itemCellListNpc    = GetItemCellsObject(tradeWindowUI.transform.GetChild(1).GetChild(0).GetChild(0).gameObject);
            _itemCellListPlayer = GetItemCellsObject(tradeWindowUI.transform.GetChild(1).GetChild(1).GetChild(0).gameObject);


            var cellIndexNpc = 1;

            foreach (var item in _itemCellListNpc)
            {
                try
                {
                    var aInt = ExtractNumberFromString(item.name);
                }
                catch
                {
                    item.name = item.name + " " + cellIndexNpc;
                    cellIndexNpc++;
                }

                var trigger = item.GetComponent <EventTrigger>();
                var entry   = new EventTrigger.Entry {
                    eventID = EventTriggerType.PointerClick
                };
                entry.callback.AddListener((data) => { OnClickItemCell(item); });

                var newTriggers = new List <EventTrigger.Entry> {
                    entry
                };

                trigger.triggers = newTriggers;
            }

            var cellIndexPlayer = 1;

            foreach (var item in _itemCellListPlayer)
            {
                try
                {
                    var aInt = ExtractNumberFromString(item.name);
                }
                catch
                {
                    item.name = item.name + " " + cellIndexPlayer;
                    cellIndexPlayer++;
                }

                var trigger = item.GetComponent <EventTrigger>();
                var entry   = new EventTrigger.Entry {
                    eventID = EventTriggerType.PointerClick
                };
                entry.callback.AddListener((data) => { OnClickItemCell(item); });

                var newTriggers = new List <EventTrigger.Entry> {
                    entry
                };

                trigger.triggers = newTriggers;
            }

            if (_lastNpcTradeInteraction != npcChar || _lastNpcTradeInteraction == null)
            {
                _npcPrices    = CalculatePrices(npcRole.inventory, npcRole.buyRate, true);
                _playerPrices = CalculatePrices(playerInv, npcRole.sellRate, false);
            }

            // Set Last Actions
            _lastNpcTradeInteraction = npcChar;

            // Update Wealth string
            UpdateNpcPlayerWealthString();

            // show items in each slots in npc
            UpdateItemSlots(_npcPrices, true);

            // show items in each slots in player
            UpdateItemSlots(_playerPrices, false);

            UpdateAmountString();
        }