コード例 #1
0
        void IJob.Execute(IJobExecutionContext context)
        {
            JobDataMap dataMap       = context.JobDetail.JobDataMap;
            string     tenantId      = dataMap.GetString("tenantId");
            int        interactionId = System.Int32.Parse(dataMap.GetString("interactionId"));

            init(tenantId);//Set Up api tenant
            //current = new Ataque.Clases.Ataque();//we must do this trought refelection searching by interaction.intName

            Interaction interaction = api.getInteractionHandler().GetInteraction(interactionId);

            if (interaction.intName.Equals("Ataque"))
            {
                current = new Ataque.Clases.Ataque();
            }
            else if (interaction.intName.Equals("Comercio"))
            {
                current = new Comercio.Clases.Comercio();
            }
            IntState intState = api.getIntStateHandler().GetIntStateByInteraction(interactionId);

            requester = GetIntFromMeta(intState.requester);
            if (intState.receiverId == -1)
            {
                receiver = GetIntFromMeta(intState.receiver);
            }
            else
            {
                receiver = GetIntFromId(intState.receiverId);
            }

            if (intState.state == SharedEntities.Enum.InteractionState.EXECUTING)//look for interaction state
            {
                int round = 1;
                List <IInteractionable> list = current.exec(requester, receiver);
                ApplyChanges(list);
                IntState state = GetIntState(interactionId, receiver, requester);
                state.state = SharedEntities.Enum.InteractionState.FINISHING;
                api.getIntStateHandler().SaveIntState(state);
                float            time = 1;
                IInteractionable i    = list.Where(c => c.mustSend() || c.getReturn()).OrderByDescending(c => c.getReturn()).FirstOrDefault();
                if (i != null)
                {
                    IDestacamento des = i.GetFlota().OrderByDescending(c => c.GetVelocidad()).FirstOrDefault();
                    time = GetDistanceBetweenColony(requester.GetID(), receiver.GetID()) / des.GetVelocidad();
                }


                Scheduler.Scheduler.ScheduleInteraction(interactionId, time, tenantId, round);
                // testExec(interactionId);
            }
            else
            {
                List <IInteractionable> list = current.finalize(requester, receiver);
                IntState state = GetIntState(interactionId, receiver, requester);
                state.state = SharedEntities.Enum.InteractionState.FINISH;
                api.getIntStateHandler().SaveIntState(state);
                ApplyChanges(list);
            }
        }
コード例 #2
0
        public InteractuableMetadata GetInteractionableMeta(IInteractionable r)
        {
            InteractuableMetadata meta = new InteractuableMetadata();

            meta.capacidad       = r.GetCapacidad();
            meta.defensa         = GetDestacamentoArrays(r.GetDefensas());
            meta.flota           = GetDestacamentoArrays(r.GetFlota());
            meta.recursos        = GetResourceArrays(r.GetRecursos());
            meta.interactuableID = r.GetID();
            return(meta);
        }
コード例 #3
0
        internal void start()
        {
            List <IInteractionable> list = current.initialize(requester, receiver);

            int interactionId = InsertInteraction(requester.GetID(), receiver.GetID());

            ApplyChanges(list);
            IntState state = GetIntState(interactionId, receiver, requester);

            api.getIntStateHandler().SaveIntState(state);

            float            time = 1;
            IInteractionable i    = list.Where(c => c.mustSend()).FirstOrDefault();

            if (i != null)
            {
                /// calculo tiempos
                IDestacamento des = i.GetFlota().OrderByDescending(c => c.GetVelocidad()).FirstOrDefault();
                time = GetDistanceBetweenColony(requester.GetID(), receiver.GetID()) / des.GetVelocidad();
            }
            int round = 0;

            Scheduler.Scheduler.ScheduleInteraction(interactionId, time, tenantId, round);
        }
コード例 #4
0
        private IntState GetIntState(int interactionId, IInteractionable receiver, IInteractionable requester)
        {
            IntState state = new IntState();

            state.interactionId = interactionId;
            if (!current.GetConfig().isRecNeedRecursos() && !current.GetConfig().isRecNeedFloat())
            {
                state.receiverId = receiver.GetID();
                state.receiver   = null;
            }
            else
            {
                state.receiverId = -1;
            }
            state.receiver  = GetInteractionableMeta(receiver);
            state.winnerId  = requester.Won() ? requester.GetID() : (receiver.Won() ? receiver.GetID() : -1);
            state.requester = GetInteractionableMeta(requester);
            return(state);
        }