public override void Process(Entity entity, Army army, GeoEntity geoEntity)
        {
            ArmyChangeEvent armyChangeEvent = new ArmyChangeEvent(army, geoEntity);
            WsMessage       wsMessage       = WsMessageBuilder.CreateWsMessage("public", armyChangeEvent);

            _jEventBus.Post(wsMessage);
        }
示例#2
0
        private long GetGeoIndex(Point structureGeoPosition)
        {
            GeoIndexReceiverEvent geoIndexReceiverEvent = new GeoIndexReceiverEvent(structureGeoPosition);

            _eventBus.Post(geoIndexReceiverEvent);
            return(geoIndexReceiverEvent.GeoIndex);
        }
示例#3
0
 public static void SendEvent(JEventBus eventBus, object eventToSend)
 {
     if (eventBus == null)
     {
         eventBus = JEventBus.GetDefault();
     }
     eventBus.Post(eventToSend);
 }
        public void AddActionToHandleListener(DynamicActionEvent dynamicActionEvent)
        {
            //TODO add more complex way to take actions
            ActionAnswer        actionAnswer        = dynamicActionEvent.ActionAnswers[0];
            ActionResponseEvent actionResponseEvent = new ActionResponseEvent(dynamicActionEvent, actionAnswer);

            _eventBus.Post(actionResponseEvent);
        }
示例#5
0
        public void Think(Entity thinker, JEventBus eventBus)
        {
            _eventBus = eventBus;
            GeoEntity geoEntity = thinker.GetComponent <GeoEntity>();
            ArmyAi    armyAi    = thinker.GetComponent <ArmyAi>();
            Army      army      = thinker.GetComponent <Army>();

            FindStructureInArea findStructureInArea = new FindStructureInArea(geoEntity.Position, armyAi.SearchRadius);

            JEventBus.GetDefault().Post(findStructureInArea);

            Entity nearestStructure = null;

            foreach (var structureEntity in findStructureInArea.Results)
            {
                Structure structure    = structureEntity.GetComponent <Structure>();
                GeoEntity structureGeo = structureEntity.GetComponent <GeoEntity>();
                long      geoIndex     = GetGeoIndex(structureGeo.Position);
                if (StructureIsVisited(geoIndex, armyAi) || structure.Fraction == army.Fraction)
                {
                    continue;
                }
                //Check accessibility
                FindPathEvent findPathEvent = new FindPathEvent(geoEntity.Position, structureGeo.Position);
                _eventBus.Post(findPathEvent);
                if (findPathEvent.CalculatedPath == null)
                {
                    continue;
                }

                nearestStructure = structureEntity;
                break;
            }

            if (nearestStructure == null)
            {
                Debug.WriteLine(army + " Skip to FindResources");
                armyAi.ArmyStateMachine.Fire(ArmyTrigger.FindResources);
                return;
            }

            armyAi.SearchRadius = 10;

            GeoEntity resourcePosition = nearestStructure.GetComponent <GeoEntity>();

            GoToEvent goToEvent = new GoToEvent(thinker, resourcePosition.Position);

            Debug.WriteLine(army + " Go For Structure: " + goToEvent.Goal);
            JEventBus.GetDefault().Post(goToEvent);

            if (goToEvent.Complete)
            {
                armyAi.VisitedStructures.Add(GetGeoIndex(resourcePosition.Position));
            }

            armyAi.ArmyStateMachine.Fire(ArmyTrigger.FinishAction);
        }
示例#6
0
        public void CreateUrbanListener(CreateUrbanEvent createUrbanEvent)
        {
            Entity resource = entityWorld.CreateEntityFromTemplate("Urban",
                                                                   createUrbanEvent.Position, createUrbanEvent.Population, createUrbanEvent.BirdsRate);

            _urbans[createUrbanEvent.Position] = resource;

            Structure structure = new Structure(new StructureDefinition("City", new Point(1, 1)));
            AddStructureOnWorldMapEvent addStructureOnWorldMap = new AddStructureOnWorldMapEvent(structure, createUrbanEvent.Position);

            _eventBus.Post(addStructureOnWorldMap);
        }
示例#7
0
        public override void Process(Entity entity, Structure structure, Mine mine)
        {
            if (structure.Fraction == null)
            {
                return;
            }

            Resource resource = new Resource(mine.ResourceDefinition, mine.Production);
            AddResourceToFractionEvent addResourceToFractionEvent = new AddResourceToFractionEvent(resource, structure.Fraction);

            _jEventBus.Post(addResourceToFractionEvent);
        }
示例#8
0
        public void Think(Entity thinker, JEventBus eventBus)
        {
            _eventBus = eventBus;
            GeoEntity geoEntity = thinker.GetComponent <GeoEntity>();
            ArmyAi    armyAi    = thinker.GetComponent <ArmyAi>();
            Army      army      = thinker.GetComponent <Army>();

            FindResourceInArea findResourceInArea = new FindResourceInArea(geoEntity.Position, armyAi.SearchRadius);

            JEventBus.GetDefault().Post(findResourceInArea);

            Entity nearestResource = null;

            foreach (var resourceEntity in findResourceInArea.Results)
            {
                Resource  resource    = resourceEntity.GetComponent <Resource>();
                GeoEntity resourceGeo = resourceEntity.GetComponent <GeoEntity>();

                FindPathEvent findPathEvent = new FindPathEvent(geoEntity.Position, resourceGeo.Position);
                _eventBus.Post(findPathEvent);
                if (findPathEvent.CalculatedPath == null)
                {
                    continue;
                }

                nearestResource = resourceEntity;
                break;
            }
            if (nearestResource == null)
            {
                armyAi.SearchRadius += 5;
                Debug.WriteLine(army + " Skip to IDLE");
                armyAi.ArmyStateMachine.Fire(ArmyTrigger.FinishAction);
                return;
            }

            armyAi.SearchRadius = 10;

            GeoEntity resourcePosition = nearestResource.GetComponent <GeoEntity>();

            GoToEvent goToEvent = new GoToEvent(thinker, resourcePosition.Position);

            Debug.WriteLine(army + " Go For Resource: " + goToEvent.Goal);
            JEventBus.GetDefault().Post(goToEvent);

            armyAi.ArmyStateMachine.Fire(ArmyTrigger.FinishAction);
        }
示例#9
0
        public void ResolveEventListener(ResolveEvent resolveEvent)
        {
            Type eventType = resolveEvent.EventTypeToResolve;

            if (!_storedEvents.Contains(eventType))
            {
                return;
            }
            _storedEvents.Remove(eventType);

            foreach (var eventToResolve in _stored[eventType])
            {
                _eventBus.Post(eventToResolve);
            }

            _stored.Remove(eventType);
        }
示例#10
0
        public static void AddMineToFraction(Point tilePosition, Fraction fraction, JEventBus eventBus = null)
        {
            if (eventBus == null)
            {
                eventBus = JEventBus.GetDefault();
            }

            FindNearestStructure findNearestStructure = new FindNearestStructure(tilePosition, 0);

            eventBus.Post(findNearestStructure);
            var entity = findNearestStructure.Nearest;

            if (entity == null)
            {
                return;
            }
            AddMineToFraction(entity, fraction, eventBus);
        }
示例#11
0
 private void ProcessClientEvent(object clientEvent)
 {
     _eventBus.Post(clientEvent);
 }
 public void LoadMap()
 {
     _mapLoader.LoadMap(EntityWorld);
     EventBus.Post(new CoreLoadedEvent());
     EventBus.Register(this);
 }