コード例 #1
0
        private void PrepareDebtTake()
        {
            try {
                NWCreature self   = (NWCreature)fSelf;
                Building   shop   = self.FindHouse();
                NWCreature debtor = null;

                Player player = GlobalVars.nwrGame.Player;
                int    debt   = player.GetDebt(self.Name);
                if (debt > 0 && self.IsAvailable(player, true) && !player.InRect(shop.Area))
                {
                    debtor = player;
                }

                DebtTakeGoal dtGoal = (DebtTakeGoal)FindGoalByKind(GoalKind.gk_DebtTake);
                if (debtor != null)
                {
                    if (dtGoal == null)
                    {
                        dtGoal = ((DebtTakeGoal)CreateGoal(GoalKind.gk_DebtTake));
                    }
                    dtGoal.Debtor = debtor;
                }
                else
                {
                    if (dtGoal != null)
                    {
                        ReleaseGoal(dtGoal);
                    }
                }
            } catch (Exception ex) {
                Logger.Write("TraderBrain.prepareDebtTake(): " + ex.Message);
            }
        }
コード例 #2
0
 private void PrepareShopReturn()
 {
     try {
         NWCreature self      = (NWCreature)fSelf;
         Building   house     = self.FindHouse();
         ExtRect    houseArea = house.Area.Clone();
         if (!houseArea.Contains(self.PosX, self.PosY) && !(FindGoalByKind(GoalKind.gk_ShopReturn) is ShopReturnGoal))
         {
             houseArea.Inflate(-1, -1);
             ShopReturnGoal srGoal = (ShopReturnGoal)CreateGoal(GoalKind.gk_ShopReturn);
             srGoal.Position = RandomHelper.GetRandomPoint(houseArea);
         }
     } catch (Exception ex) {
         Logger.Write("TraderBrain.prepareReturn(): " + ex.Message);
     }
 }
コード例 #3
0
        protected override void EvaluateGoal(GoalEntity goal)
        {
            try {
                NWCreature self = (NWCreature)fSelf;
                int        gk   = goal.Kind;

                switch (gk)
                {
                case GoalKind.gk_ShopReturn:
                    goal.Value = 0.23f;
                    break;

                case GoalKind.gk_DebtTake:
                {
                    DebtTakeGoal dtGoal = (DebtTakeGoal)goal;
                    if (self.IsAvailable(dtGoal.Debtor, true))
                    {
                        goal.Value = 1f;
                    }
                    else
                    {
                        goal.Value = 0.1f;
                    }
                }
                break;

                case GoalKind.gk_WareReturn:
                    Building house = (Building)self.FindHouse();
                    if (house.Area.Contains(self.PosX, self.PosY))
                    {
                        goal.Value = 0.9f;
                    }
                    else
                    {
                        goal.Value = 0.22f;
                    }
                    break;

                default:
                    base.EvaluateGoal(goal);
                    break;
                }
            } catch (Exception ex) {
                Logger.Write("TraderBrain.evaluateGoal(): " + ex.Message);
            }
        }
コード例 #4
0
        public override void Execute()
        {
            NWCreature self = (NWCreature)Self;

            try {
                Building house   = self.FindHouse();
                Door     gp      = null;
                int      dist    = 0;
                bool     outside = false;
                house.IsNearestDoor(self.PosX, self.PosY, ref gp, ref dist, ref outside);

                if (outside && gp != null)
                {
                    if (dist == 1)
                    {
                        Brain.StepTo(gp.X, gp.Y);
                    }
                    else
                    {
                        ExtPoint tempPos = new ExtPoint();
                        tempPos.X = gp.X + Directions.Data[gp.Dir].DX;
                        tempPos.Y = gp.Y + Directions.Data[gp.Dir].DY;
                        ExtPoint next = self.GetStep(tempPos);
                        if (!next.IsEmpty)
                        {
                            Brain.StepTo(next.X, next.Y);
                        }
                    }
                }
                else
                {
                    ExtPoint next = self.GetStep(Position);
                    if (!next.IsEmpty)
                    {
                        Brain.StepTo(next.X, next.Y);
                    }
                }

                IsComplete = self.Location.Equals(Position);
            } catch (Exception ex) {
                Logger.Write("ShopReturnGoal.execute(): " + ex.Message);
            }
        }
コード例 #5
0
        public override void Execute()
        {
            NWCreature self = (NWCreature)Self;

            try {
                Building house = self.FindHouse();
                if (house.Area.Contains(self.PosX, self.PosY))
                {
                    self.DropItem(Ware);
                    IsComplete = true;
                }
                else
                {
                    IsComplete = false;
                }
            } catch (Exception ex) {
                Logger.Write("WareReturnGoal.execute(): " + ex.Message);
            }
        }
コード例 #6
0
        private void UpdateEquipmentLists()
        {
            try {
                fPackList.Items.Clear();
                fEquipList.Items.Clear();
                fOutList.Items.Clear();

                bool    onlyIcons = GlobalVars.nwrWin.InventoryOnlyIcons;
                Player  player    = GlobalVars.nwrGame.Player;
                NWField fld       = player.CurrentField;
                bool    blindness = player.Blindness;

                int debt = 0;
                fMode = IWMODE_GROUND;
                if (Collocutor != null)
                {
                    debt = player.GetDebt(Collocutor.Name);
                    if (Collocutor.IsTrader)
                    {
                        Building house = (Building)Collocutor.FindHouse();

                        if (house.Area.Contains(player.PosX, player.PosY))
                        {
                            fMode = IWMODE_INSHOP;
                        }
                        else
                        {
                            fMode = IWMODE_TRADER;
                        }
                    }
                    else
                    {
                        if (Collocutor.Mercenary)
                        {
                            fMode = IWMODE_MERCENARY;
                        }
                    }
                }

                fPayBtn.Enabled = (fMode != IWMODE_GROUND && debt != 0);

                switch (fMode)
                {
                case IWMODE_GROUND:
                {
                    EntityList items = player.Items;

                    int num5 = items.Count;
                    for (int i = 0; i < num5; i++)
                    {
                        Item item = (Item)items.GetItem(i);
                        if (!item.Identified && player.Memory.Find(item.Entry.Sign) != null)
                        {
                            item.Identified = true;
                        }

                        if (item.Equipment && item.InUse && fContainer == null)
                        {
                            AddListItem(fEquipList, item.GetName(blindness), item, onlyIcons);
                        }
                        else
                        {
                            AddListItem(fPackList, item.GetName(blindness), item, onlyIcons);
                        }
                    }

                    ExtList <LocatedEntity> groundItems = fld.Items.SearchListByPos(player.PosX, player.PosY);

                    int num6 = groundItems.Count;
                    for (int i = 0; i < num6; i++)
                    {
                        Item item = (Item)groundItems[i];
                        if (!item.Identified && player.Memory.Find(item.Entry.Sign) != null)
                        {
                            item.Identified = true;
                        }
                        AddListItem(fOutList, item.GetName(blindness), item, onlyIcons);
                    }
                    groundItems.Dispose();
                }
                break;

                case IWMODE_TRADER:
                case IWMODE_INSHOP:
                {
                    EntityList items = player.Items;

                    int num3 = items.Count;
                    for (int i = 0; i < num3; i++)
                    {
                        Item item = (Item)items.GetItem(i);
                        if (!item.Identified && player.Memory.Find(item.Entry.Sign) != null)
                        {
                            item.Identified = true;
                        }

                        if (item.Equipment && item.InUse && fContainer == null)
                        {
                            AddListItem(fEquipList, item.GetName(blindness), item, onlyIcons);
                        }
                        else
                        {
                            if (item.Ware)
                            {
                                AddListItem(fPackList, item.GetName(blindness) + " (" + Convert.ToString((int)item.GetTradePrice(Collocutor, player)) + "$)", item, onlyIcons);
                            }
                            else
                            {
                                AddListItem(fPackList, item.GetName(blindness), item, onlyIcons);
                            }
                        }
                    }

                    Building house = fld.FindBuilding(player.PosX, player.PosY);
                    if (house != null)
                    {
                        if (debt > 0)
                        {
                            house.SwitchDoors(DoorState.Closed);
                        }
                        else
                        {
                            house.SwitchDoors(DoorState.Opened);
                        }
                        ExtList <LocatedEntity> groundItems = fld.Items.SearchListByArea(house.Area);

                        int num4 = groundItems.Count;
                        for (int i = 0; i < num4; i++)
                        {
                            Item item = (Item)groundItems[i];
                            item.Identified = true;
                            AddListItem(fOutList, item.GetName(blindness) + " (" + Convert.ToString((int)item.GetTradePrice(player, Collocutor)) + "$)", item, onlyIcons);
                        }

                        groundItems.Dispose();
                    }
                }
                break;

                case IWMODE_MERCENARY:
                {
                    EntityList items = player.Items;

                    int num = items.Count;
                    for (int i = 0; i < num; i++)
                    {
                        Item item = (Item)items.GetItem(i);
                        if (!item.Identified && player.Memory.Find(item.Entry.Sign) != null)
                        {
                            item.Identified = true;
                        }
                        if (item.Equipment && item.InUse && fContainer == null)
                        {
                            AddListItem(fEquipList, item.GetName(blindness), item, onlyIcons);
                        }
                        else
                        {
                            if (item.Ware)
                            {
                                AddListItem(fPackList, item.GetName(blindness) + " (" + Convert.ToString(item.Price) + "$)", item, onlyIcons);
                            }
                            else
                            {
                                AddListItem(fPackList, item.GetName(blindness), item, onlyIcons);
                            }
                        }
                    }
                    items = Collocutor.Items;

                    int num2 = items.Count;
                    for (int i = 0; i < num2; i++)
                    {
                        Item item = (Item)items.GetItem(i);
                        AddListItem(fOutList, item.GetName(blindness) + " (" + Convert.ToString(item.Price) + "$)", item, onlyIcons);
                    }
                }
                break;
                }

                if (fContainer != null)
                {
                    EntityList items = fContainer.Contents;

                    int num7 = items.Count;
                    for (int i = 0; i < num7; i++)
                    {
                        Item item = (Item)items.GetItem(i);
                        if (!item.Identified && player.Memory.Find(item.Entry.Sign) != null)
                        {
                            item.Identified = true;
                        }
                        AddListItem(fEquipList, item.GetName(blindness), item, onlyIcons);
                    }
                }
            } catch (Exception ex) {
                Logger.Write("InventoryWindow.updateEquipmentLists(): " + ex.Message);
                throw ex;
            }
        }