Пример #1
0
        public ITroopObject CreateTroopObject(ITroopStub stub, uint x, uint y)
        {
            var troopObject = gameObjectFactory.CreateTroopObject(objectIdGen.GetNext(), stub, x, y, TroopTheme);

            Add(troopObject.ObjectId, troopObject, true);
            return(troopObject);
        }
Пример #2
0
        public void Generate(int count)
        {
            for (var i = 0; i < count; ++i)
            {
                string name;
                byte   level;
                uint   x, y;

                if (!strongholdConfigurator.Next(i, count, out name, out level, out x, out y))
                {
                    break;
                }

                var         limit      = formula.StrongholdGateLimit(level);
                IStronghold stronghold = strongholdFactory.CreateStronghold(idGenerator.GetNext(),
                                                                            name,
                                                                            level,
                                                                            x,
                                                                            y,
                                                                            limit,
                                                                            Convert.ToInt32(limit),
                                                                            Theme.DEFAULT_THEME_ID);

                using (dbManager.GetThreadTransaction())
                {
                    Add(stronghold);
                }
            }
        }
Пример #3
0
        public void Generate()
        {
            var sw = new Stopwatch();

            sw.Start();

            foreach (var newBarbarianTribeConfiguration in barbarianTribeConfigurator.Create(AllTribes, Count))
            {
                var newBarbarianTribe = barbarianTribeFactory.CreateBarbarianTribe(idGenerator.GetNext(),
                                                                                   newBarbarianTribeConfiguration.Level,
                                                                                   newBarbarianTribeConfiguration.PrimaryPosition,
                                                                                   Config.barbariantribe_camp_count);

                multiObjectLockFactory().Lock(new ILockable[] { newBarbarianTribe })
                .Do(() => Add(newBarbarianTribe));

                logger.Info(string.Format("Added barbarianTribe[{0},{1}] Number[{2}] ",
                                          newBarbarianTribe.PrimaryPosition.X,
                                          newBarbarianTribe.PrimaryPosition.Y,
                                          Count));
            }

            sw.Stop();
            logger.Info("Completed generating barb camps in {0}", sw.Elapsed);
        }
Пример #4
0
        public void Add(IGameObject referenceObject, PassiveAction action)
        {
            PassiveAction workingStub;

            if (!actionWorker.PassiveActions.TryGetValue(action.ActionId, out workingStub))
            {
                throw new Exception("Action not found");
            }

            var newReference = new ReferenceStub((ushort)referenceIdGen.GetNext(), referenceObject, workingStub, cityId);

            reference.Add(newReference);
            dbManager.Save(newReference);

            ReferenceAdded(this, new ActionReferenceArgs {
                ReferenceStub = newReference
            });
        }
Пример #5
0
        public void Add(ITribe tribe)
        {
            tribe.Id = tribeIdGen.GetNext();
            if (!Tribes.TryAdd(tribe.Id, tribe))
            {
                return;
            }

            dbManager.Save(tribe);

            SubscribeEvents(tribe);
        }
Пример #6
0
        public void CreateForestAt(int capacity, uint x = 0, uint y = 0)
        {
            lock (forests)
            {
                if (x == 0 || y == 0)
                {
                    while (true)
                    {
                        x = (uint)Config.Random.Next(5, (int)Config.map_width - 5);
                        y = (uint)Config.Random.Next(5, (int)Config.map_height - 5);

                        if (mapFactory.TooCloseToCities(new Position(x, y), 1))
                        {
                            continue;
                        }

                        world.Regions.LockRegion(x, y);

                        // check if near any other objects
                        if (world.Regions.GetObjectsInTile(x, y).Any(obj => !(obj is ITroopObject)) ||
                            world.Regions.GetObjectsWithin(x, y, 1).Any(obj => !(obj is ITroopObject)))
                        {
                            world.Regions.UnlockRegion(x, y);
                            continue;
                        }

                        break;
                    }
                }
                else
                {
                    world.Regions.LockRegion(x, y);
                }

                var forest = forestFactory.CreateForest(objectIdGenerator.GetNext(), capacity, x, y);

                forest.BeginUpdate();
                world.Regions.Add(forest);
                world.Regions.UnlockRegion(x, y);
                forests.TryAdd(forest.ObjectId, forest);
                forest.RecalculateForest();
                forest.EndUpdate();
            }
        }
Пример #7
0
        /// <summary>
        ///     Creates a new assignment.
        ///     An id will be assigned and the stub passed in will be added to the assignment. This will not schedule the assignment!
        /// </summary>
        public Assignment(ITribe tribe,
                          uint x,
                          uint y,
                          ILocation target,
                          AttackMode mode,
                          DateTime targetTime,
                          string description,
                          bool isAttack,
                          Formula formula,
                          IDbManager dbManager,
                          IGameObjectLocator gameObjectLocator,
                          IScheduler scheduler,
                          Procedure procedure,
                          ITileLocator tileLocator,
                          IActionFactory actionFactory,
                          ILocker locker,
                          ITroopObjectInitializerFactory troopObjectInitializerFactory)
        {
            this.formula                       = formula;
            this.dbManager                     = dbManager;
            this.gameObjectLocator             = gameObjectLocator;
            this.scheduler                     = scheduler;
            this.procedure                     = procedure;
            this.tileLocator                   = tileLocator;
            this.actionFactory                 = actionFactory;
            this.locker                        = locker;
            this.troopObjectInitializerFactory = troopObjectInitializerFactory;

            Id            = (int)IdGen.GetNext();
            Tribe         = tribe;
            TargetTime    = targetTime;
            Target        = target;
            X             = x;
            Y             = y;
            AttackMode    = mode;
            DispatchCount = 0;
            Description   = description;
            IsAttack      = isAttack;
        }
Пример #8
0
        public Error DoActive(int workerType, IGameObject workerObject, ActiveAction action, IHasEffect effects)
        {
            if (workerObject.IsBlocked > 0)
            {
                return(Error.ObjectNotFound);
            }

            uint actionId = actionIdGen.GetNext();

            ActionRequirementFactory.ActionRecord record =
                Ioc.Kernel.Get <ActionRequirementFactory>().GetActionRequirementRecord(workerType);

            if (record == null)
            {
                return(Error.ActionNotFound);
            }

            foreach (var actionReq in record.List.Where(x => x.Type == action.Type))
            {
                var error = action.Validate(actionReq.Parms);

                if (error != Error.Ok)
                {
                    if (error != Error.ActionInvalid)
                    {
                        return(error);
                    }

                    continue;
                }

                if (!CanDoActiveAction(action, actionReq, workerObject))
                {
                    return(Error.ActionTotalMaxReached);
                }

                error =
                    Ioc.Kernel.Get <EffectRequirementFactory>()
                    .GetEffectRequirementContainer(actionReq.EffectReqId)
                    .Validate(workerObject, effects.GetAllEffects(actionReq.EffectReqInherit), requirementFormula);

                if (error != Error.Ok)
                {
                    return(error);
                }

                SetActiveActionParams(action);

                action.ActionId     = actionId;
                action.WorkerIndex  = actionReq.Index;
                action.WorkerType   = workerType;
                action.WorkerObject = workerObject;
                active.Add(action.ActionId, action);

                Error ret = action.Execute();

                if (ret != Error.Ok)
                {
                    action.StateChange(ActionState.Failed);
                    active.Remove(action.ActionId);
                    actionIdGen.Release(action.ActionId);
                }
                else
                {
                    action.StateChange(ActionState.Started);
                }

                return(ret);
            }

            return(Error.ActionInvalid);
        }
Пример #9
0
 public uint GetNextCombatObjectId()
 {
     return(idGen.GetNext());
 }
Пример #10
0
 public uint GetNextGroupId()
 {
     return(groupIdGen.GetNext());
 }
Пример #11
0
 public uint GetNextCityId()
 {
     return(cityIdGen.GetNext());
 }