Exemple #1
0
 public void ExecuteTransferResource(BoosterEffect effect)
 {
     if (effect.Transfer == null)
     {
         return;
     }
     for (int i = 0; i < effect.Transfer.Length; i++)
     {
         BoosterEffect.TransferResource transferResource = effect.Transfer[i];
         if (string.IsNullOrEmpty(transferResource.ResourceName))
         {
             Diagnostics.LogWarning("Booster '{0}': Transfer number {1} resource name is null or empty.", new object[]
             {
                 this.BoosterDefinition.Name,
                 i
             });
         }
         else
         {
             DepartmentOfTheTreasury agency = this.empire.GetAgency <DepartmentOfTheTreasury>();
             if (agency != null)
             {
                 agency.TryTransferResources(this.Context, transferResource.ResourceName, (float)transferResource.Amount);
             }
         }
     }
 }
Exemple #2
0
    public IEnumerable <SimulationDescriptor> GetDescriptors()
    {
        int num;

        for (int index = 0; index < this.BoosterDefinition.Descriptors.Length; index = num + 1)
        {
            yield return(this.BoosterDefinition.Descriptors[index]);

            num = index;
        }
        if (this.BoosterDefinition.Effects != null)
        {
            for (int index = 0; index < this.BoosterDefinition.Effects.Length; index = num + 1)
            {
                BoosterEffect effect = this.BoosterDefinition.Effects[index];
                if (Booster.CheckPrerequisites(effect, this.Context))
                {
                    for (int i = 0; i < effect.SimulationDescriptors.Length; i = num + 1)
                    {
                        yield return(effect.SimulationDescriptors[i]);

                        num = i;
                    }
                }
                effect = null;
                num    = index;
            }
        }
        yield break;
    }
Exemple #3
0
    public void Activate()
    {
        if (!Booster.CanActivate(this.BoosterDefinition, this.Context))
        {
            return;
        }
        if (this.IsActive())
        {
            this.OnReactivation();
            if (this.BoosterDefinition.BoosterType == BoosterDefinition.Type.ResettingTime)
            {
                return;
            }
        }
        else
        {
            if (this.BoosterDefinition.BoosterType == BoosterDefinition.Type.Instant)
            {
                this.Duration = 0;
            }
            else
            {
                this.TurnWhenStarted = this.game.Turn;
                this.Context.AddChild(this);
                this.ApplyClassTimedDescriptor();
                this.ApplyDescriptors(true);
                this.RemainingTime = this.Duration;
            }
            this.ApplyEffects();
            this.Context.Refresh(false);
        }
        if (this.game != null)
        {
            IVisibilityService service = this.game.Services.GetService <IVisibilityService>();
            if (service != null && this.empire != null)
            {
                service.NotifyVisibilityHasChanged(this.empire);
            }
        }
        if (this.BoosterDefinition.Effects != null)
        {
            for (int i = 0; i < this.BoosterDefinition.Effects.Length; i++)
            {
                BoosterEffect effect = this.BoosterDefinition.Effects[i];
                if (Booster.CheckPrerequisites(effect, this.Context))
                {
                    this.ExecuteCommands(effect);
                }
            }
        }
        IEventService service2 = Services.GetService <IEventService>();

        if (service2 != null)
        {
            service2.Notify(new EventBoosterActivated(this.empire, this));
        }
    }
Exemple #4
0
        public override void ApplyBoosterEffect(BoosterEffect boosterEffect)
        {
            switch (boosterEffect.Type)
            {
            case BoosterType.ChangeBallSpeed:
                MultiplySpeed(boosterEffect.Amount);
                break;

            default:
                break;
            }
        }
Exemple #5
0
 public static bool CheckPrerequisites(BoosterEffect effect, SimulationObjectWrapper context)
 {
     if (effect.Prerequisites == null || effect.Prerequisites.Length == 0)
     {
         return(true);
     }
     for (int i = 0; i < effect.Prerequisites.Length; i++)
     {
         if (!effect.Prerequisites[i].Check(context))
         {
             return(false);
         }
     }
     return(true);
 }
Exemple #6
0
 public void RemoveEffects()
 {
     if (this.BoosterDefinition.Effects == null)
     {
         return;
     }
     for (int i = 0; i < this.BoosterDefinition.Effects.Length; i++)
     {
         BoosterEffect boosterEffect = this.BoosterDefinition.Effects[i];
         if (boosterEffect.SimulationDescriptors != null)
         {
             for (int j = 0; j < boosterEffect.SimulationDescriptors.Length; j++)
             {
                 base.RemoveDescriptor(boosterEffect.SimulationDescriptors[j]);
             }
         }
     }
 }
Exemple #7
0
 public void ApplyEffects()
 {
     if (this.BoosterDefinition.Effects == null)
     {
         return;
     }
     for (int i = 0; i < this.BoosterDefinition.Effects.Length; i++)
     {
         BoosterEffect boosterEffect = this.BoosterDefinition.Effects[i];
         if (Booster.CheckPrerequisites(boosterEffect, this.Context))
         {
             this.ExecuteTransferResource(boosterEffect);
             if (boosterEffect.SimulationDescriptors != null)
             {
                 for (int j = 0; j < boosterEffect.SimulationDescriptors.Length; j++)
                 {
                     base.AddDescriptor(boosterEffect.SimulationDescriptors[j], false);
                 }
             }
         }
     }
 }
Exemple #8
0
 public abstract void ApplyBoosterEffect(BoosterEffect boosterEffect);
Exemple #9
0
    public void ExecuteCommands(BoosterEffect effect)
    {
        if (effect.Commands == null || effect.Commands.Length == 0)
        {
            return;
        }
        global::PlayerController server = this.empire.PlayerControllers.Server;

        if (server == null)
        {
            return;
        }
        for (int i = 0; i < effect.Commands.Length; i++)
        {
            BoosterEffect.Command command = effect.Commands[i];
            if (command != null && !string.IsNullOrEmpty(command.Name))
            {
                List <StaticString> list = new List <StaticString>();
                for (int j = 0; j < command.Arguments.Length; j++)
                {
                    list.Add(command.Arguments[j]);
                }
                string name = command.Name;
                if (name != null)
                {
                    if (Booster.< > f__switch$map12 == null)
                    {
                        Booster.< > f__switch$map12 = new Dictionary <string, int>(1)
                        {
                            {
                                "CreateUnit",
                                0
                            }
                        };
                    }
                    int num;
                    if (Booster.< > f__switch$map12.TryGetValue(name, out num))
                    {
                        if (num == 0)
                        {
                            for (int k = 0; k < list.Count; k++)
                            {
                                OrderSpawnUnit order = new OrderSpawnUnit(this.empire.Index, 0, true, list[k], this.TargetGUID, command.AllowGarrisonOverflow);
                                server.PostOrder(order);
                                if (effect.SimulationDescriptorReferences.Any((SimulationDescriptorReference descriptor) => descriptor.Name == AchievementManager.BattlebornDesignName))
                                {
                                    IEventService service = Services.GetService <IEventService>();
                                    if (service != null)
                                    {
                                        EventBattlebornCreated eventToNotify = new EventBattlebornCreated(this.empire);
                                        service.Notify(eventToNotify);
                                    }
                                }
                            }
                            goto IL_1A6;
                        }
                    }
                }
                Diagnostics.LogWarning("No process defined for command '{0}'", new object[]
                {
                    command.Name
                });
            }
            IL_1A6 :;
        }
    }