Exemplo n.º 1
0
 /// -------------------------------------------------------------------------------------------------------------------------------------------------------------
 /// Start
 /// -------------------------------------------------------------------------------------------------------------------------------------------------------------
 /// <summary> The Start method of MonoBehaviour class. </summary>
 private void Start()
 {
     // Sprite renderer component is gotten here.
     spriteRenderer = GetComponent <SpriteRenderer>();
     // Dynamic unit instance is created here.
     dynamicUnit = new DynamicUnit(SizeXSoldier, SizeYSoldier, colorUnit, Managers.Instance.gridManager.Grids);
 }
Exemplo n.º 2
0
    /// <summary>
    /// 添加设置动态unit到关联子unit列表
    /// </summary>
    /// <param name="position"></param>
    /// <param name="orient"></param>
    /// <param name="unit"></param>
    public void SetDynamicLink(Vector3 position, float orient, DynamicUnit unit)
    {
        if (unit == null)
        {
            return;
        }
        if (this.destroyed || unit.destroyed || this.scene.mapPath == null)
        {
            return;
        }
        if (this.mDynState == DynamicState.LINK_CHILD)
        {
            this.mDynState = DynamicState.LINK_PARENT_CHILD;
        }
        else if (this.mDynState == DynamicState.NULL)
        {
            this.mDynState = DynamicState.LINK_PARENT;
        }
        if (this.linkUnits == null)
        {
            this.linkUnits = new List <DynamicLinkUnit>();
        }
        int             count           = this.linkUnits.Count;
        DynamicLinkUnit dynamicLinkUnit = null;

        for (int i = 0; i < count; i++)
        {
            if (this.linkUnits[i] != null && this.linkUnits[i].mDynamic != null && this.linkUnits[i].mDynamic == unit)
            {
                dynamicLinkUnit = this.linkUnits[i];
                break;
            }
        }
        if (dynamicLinkUnit == null)
        {
            dynamicLinkUnit = new DynamicLinkUnit(unit);
            this.linkUnits.Add(dynamicLinkUnit);
        }
        else
        {
            dynamicLinkUnit.Init();
        }
        if (unit.mDynState == DynamicState.LINK_PARENT)
        {
            unit.mDynState = DynamicState.LINK_PARENT_CHILD;
        }
        else
        {
            unit.mDynState = DynamicState.LINK_CHILD;
        }
        Vector3 eulerAngles = this.rotation.eulerAngles;

        dynamicLinkUnit.SetPositionAndOrient(position, orient);
        Vector3 vector  = this.position + dynamicLinkUnit.GetPosition(eulerAngles.y);
        float   orient2 = eulerAngles.y * 0.0174532924f + orient;

        unit.OnLinkLocation(vector, orient2);          //子Unit放置到位置
    }
Exemplo n.º 3
0
 public DynamicLinkUnit(DynamicUnit unit)
 {
     this.mDynamic                  = unit;
     this.isMainUint                = unit.isMainUint;
     this.genRipple                 = unit.genRipple;
     this.needSampleHeight          = unit.needSampleHeight;
     this.mDynamic.isMainUint       = false;
     this.mDynamic.genRipple        = false;
     this.mDynamic.needSampleHeight = false;
 }
Exemplo n.º 4
0
    /// <summary>
    /// 移除指定的子unit
    /// </summary>
    /// <param name="unit"></param>
    public void RemoveLinkDynamic(DynamicUnit unit)
    {
        int count = this.linkUnits.Count;

        for (int i = 0; i < count; i++)
        {
            if (this.linkUnits[i] != null && this.linkUnits[i].mDynamic != null && this.linkUnits[i].mDynamic == unit)
            {
                this.linkUnits[i].Remove();
                this.linkUnits.RemoveAt(i);
                break;
            }
        }
        if (this.linkUnits.Count == 0)
        {
            this.mDynState = DynamicState.NULL;
        }
    }
Exemplo n.º 5
0
    /// <summary>
    /// 创建动态Unit
    /// </summary>
    /// <param name="scene"></param>
    /// <param name="pos"></param>
    /// <param name="createID"></param>
    /// <param name="prePath"></param>
    /// <param name="radius"></param>
    /// <param name="dynamiCullingDistance"></param>
    /// <returns></returns>
    public static DynamicUnit Create(GameScene scene, Vector3 pos, int createID, string prePath, float radius, float dynamiCullingDistance = -1f)
    {
        DynamicUnit dynamicUnit = new DynamicUnit(createID);

        dynamicUnit.scene    = scene;
        dynamicUnit.position = pos;
        dynamicUnit.prePath  = prePath;
        dynamicUnit.radius   = radius;
        if (dynamiCullingDistance > 0f)
        {
            dynamicUnit.near = dynamiCullingDistance;
        }
        else
        {
            dynamicUnit.near = scene.terrainConfig.dynamiCullingDistance;
        }
        dynamicUnit.far = dynamicUnit.near + 2f;
        return(dynamicUnit);
    }
 // Token: 0x060004CD RID: 1229 RVA: 0x00019434 File Offset: 0x00017634
 protected override void OnAbilityAdded(Ability9 entity)
 {
     try
     {
         ActiveAbility activeAbility;
         if (entity.IsControllable && entity.Owner.CanUseAbilities && entity.Owner.IsAlly(this.owner) && (activeAbility = (entity as ActiveAbility)) != null)
         {
             Unit9     abilityOwner = entity.Owner;
             Morphling morphling    = entity.Owner as Morphling;
             if (morphling != null && morphling.IsMorphed)
             {
                 ControllableUnit controllableUnit;
                 Type             type;
                 if (this.unitTypes.TryGetValue(morphling.MorphedHero.Name, out type))
                 {
                     controllableUnit = this.controllableUnits.Find((ControllableUnit x) => x.Handle == abilityOwner.Handle && x.GetType() == type);
                     if (controllableUnit == null)
                     {
                         controllableUnit = (ControllableUnit)Activator.CreateInstance(type, new object[]
                         {
                             abilityOwner,
                             this.abilitySleeper,
                             this.orbwalkSleeper[abilityOwner.Handle],
                             base.GetUnitMenu(abilityOwner)
                         });
                         controllableUnit.FailSafe        = base.BaseHero.FailSafe;
                         controllableUnit.MorphedUnitName = morphling.MorphedHero.Name;
                         foreach (ActiveAbility ability in (from x in abilityOwner.Abilities
                                                            where x.IsItem
                                                            select x).OfType <ActiveAbility>())
                         {
                             controllableUnit.AddAbility(ability, base.BaseHero.ComboMenus, base.BaseHero.MoveComboModeMenu);
                         }
                         this.controllableUnits.Add(controllableUnit);
                     }
                 }
                 else
                 {
                     controllableUnit = this.controllableUnits.Find((ControllableUnit x) => x.Handle == abilityOwner.Handle && x is DynamicUnit);
                     if (controllableUnit == null)
                     {
                         controllableUnit = new DynamicUnit(abilityOwner, this.abilitySleeper, this.orbwalkSleeper[abilityOwner.Handle], base.GetUnitMenu(abilityOwner), base.BaseHero)
                         {
                             FailSafe        = base.BaseHero.FailSafe,
                             MorphedUnitName = morphling.MorphedHero.Name
                         };
                         foreach (ActiveAbility ability2 in (from x in abilityOwner.Abilities
                                                             where x.IsItem
                                                             select x).OfType <ActiveAbility>())
                         {
                             controllableUnit.AddAbility(ability2, base.BaseHero.ComboMenus, base.BaseHero.MoveComboModeMenu);
                         }
                         this.controllableUnits.Add(controllableUnit);
                     }
                 }
                 if (activeAbility.IsItem)
                 {
                     IEnumerable <ControllableUnit> controllableUnits = this.controllableUnits;
                     Func <ControllableUnit, bool>  predicate;
                     Func <ControllableUnit, bool> < > 9__4;
                     if ((predicate = < > 9__4) == null)
                     {
                         predicate = (< > 9__4 = ((ControllableUnit x) => x.Handle == abilityOwner.Handle));
                     }
                     using (IEnumerator <ControllableUnit> enumerator2 = controllableUnits.Where(predicate).GetEnumerator())
                     {
                         while (enumerator2.MoveNext())
                         {
                             ControllableUnit controllableUnit2 = enumerator2.Current;
                             controllableUnit2.AddAbility(activeAbility, base.BaseHero.ComboMenus, base.BaseHero.MoveComboModeMenu);
                         }
                         goto IL_3D3;
                     }
                 }
                 controllableUnit.AddAbility(activeAbility, base.BaseHero.ComboMenus, base.BaseHero.MoveComboModeMenu);
                 IL_3D3 :;
             }
             else
             {
                 if (activeAbility.IsItem)
                 {
                     IEnumerable <ControllableUnit> controllableUnits2 = this.controllableUnits;
                     Func <ControllableUnit, bool>  predicate2;
                     Func <ControllableUnit, bool> < > 9__5;
                     if ((predicate2 = < > 9__5) == null)
                     {
                         predicate2 = (< > 9__5 = ((ControllableUnit x) => x.Handle == abilityOwner.Handle));
                     }
                     using (IEnumerator <ControllableUnit> enumerator2 = controllableUnits2.Where(predicate2).GetEnumerator())
                     {
                         while (enumerator2.MoveNext())
                         {
                             ControllableUnit controllableUnit3 = enumerator2.Current;
                             controllableUnit3.AddAbility(activeAbility, base.BaseHero.ComboMenus, base.BaseHero.MoveComboModeMenu);
                         }
                         goto IL_488;
                     }
                 }
                 ControllableUnit controllableUnit4 = this.controllableUnits.Find((ControllableUnit x) => x.Handle == entity.Owner.Handle);
                 if (controllableUnit4 != null)
                 {
                     controllableUnit4.AddAbility(activeAbility, base.BaseHero.ComboMenus, base.BaseHero.MoveComboModeMenu);
                 }
                 IL_488 :;
             }
         }
     }
     catch (Exception ex)
     {
         Logger.Error(ex, null);
     }
 }
Exemplo n.º 7
0
        protected override void OnAbilityAdded(Ability9 entity)
        {
            try
            {
                if (!entity.IsControllable || entity.IsFake || !entity.Owner.IsAlly(this.owner.Team) ||
                    !(entity is ActiveAbility activeAbility))
                {
                    return;
                }

                var abilityOwner = entity.Owner;
                var morph        = entity.Owner as Morphling;

                if (morph?.IsMorphed == true)
                {
                    ControllableUnit morphedUnit;

                    if (this.unitTypes.TryGetValue(morph.MorphedHero.Name, out var type))
                    {
                        morphedUnit = this.controllableUnits.Find(x => x.Handle == abilityOwner.Handle && x.GetType() == type);

                        if (morphedUnit == null)
                        {
                            morphedUnit = (ControllableUnit)Activator.CreateInstance(
                                type,
                                abilityOwner,
                                this.abilitySleeper,
                                this.orbwalkSleeper[abilityOwner.Handle],
                                this.GetUnitMenu(abilityOwner));
                            morphedUnit.FailSafe        = this.BaseHero.FailSafe;
                            morphedUnit.MorphedUnitName = morph.MorphedHero.Name;

                            foreach (var item in abilityOwner.Abilities.Where(x => x.IsItem).OfType <ActiveAbility>())
                            {
                                morphedUnit.AddAbility(item, this.BaseHero.ComboMenus, this.BaseHero.MoveComboModeMenu);
                            }

                            this.controllableUnits.Add(morphedUnit);
                        }
                    }
                    else
                    {
                        morphedUnit = this.controllableUnits.Find(x => x.Handle == abilityOwner.Handle && x is DynamicUnit);

                        if (morphedUnit == null)
                        {
                            morphedUnit = new DynamicUnit(
                                abilityOwner,
                                this.abilitySleeper,
                                this.orbwalkSleeper[abilityOwner.Handle],
                                this.GetUnitMenu(abilityOwner),
                                this.BaseHero)
                            {
                                FailSafe        = this.BaseHero.FailSafe,
                                MorphedUnitName = morph.MorphedHero.Name
                            };
                            foreach (var item in abilityOwner.Abilities.Where(x => x.IsItem).OfType <ActiveAbility>())
                            {
                                morphedUnit.AddAbility(item, this.BaseHero.ComboMenus, this.BaseHero.MoveComboModeMenu);
                            }

                            this.controllableUnits.Add(morphedUnit);
                        }
                    }

                    if (activeAbility.IsItem)
                    {
                        foreach (var controllableUnit in this.controllableUnits.Where(x => x.Handle == abilityOwner.Handle))
                        {
                            controllableUnit.AddAbility(activeAbility, this.BaseHero.ComboMenus, this.BaseHero.MoveComboModeMenu);
                        }
                    }
                    else
                    {
                        morphedUnit.AddAbility(activeAbility, this.BaseHero.ComboMenus, this.BaseHero.MoveComboModeMenu);
                    }

                    return;
                }

                if (activeAbility.IsItem)
                {
                    foreach (var controllable in this.controllableUnits.Where(x => x.Handle == abilityOwner.Handle))
                    {
                        controllable.AddAbility(activeAbility, this.BaseHero.ComboMenus, this.BaseHero.MoveComboModeMenu);
                    }
                }
                else
                {
                    var controllable = this.controllableUnits.Find(x => x.Handle == entity.Owner.Handle);
                    controllable?.AddAbility(activeAbility, this.BaseHero.ComboMenus, this.BaseHero.MoveComboModeMenu);
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
            }
        }
Exemplo n.º 8
0
        private void OnUnitAdded(Unit9 entity)
        {
            try
            {
                if (!entity.IsControllable || !entity.IsAlly(this.owner.Team))
                {
                    return;
                }

                if (this.ignoredUnits.Contains(entity.Name) || this.controllableUnits.Any(x => x.Handle == entity.Handle))
                {
                    return;
                }

                if (!this.controlAllies)
                {
                    if (entity.IsHero)
                    {
                        if (entity.BaseOwner?.Handle != this.owner.PlayerHandle)
                        {
                            return;
                        }
                    }
                    else if (entity.BaseOwner?.Handle != this.owner.HeroHandle)
                    {
                        return;
                    }
                }

                if (!entity.CanUseAbilities || !this.unitTypes.TryGetValue(entity.Name, out var type))
                {
                    if (entity.CanUseAbilities)
                    {
                        var d = new DynamicUnit(
                            entity,
                            this.abilitySleeper,
                            this.orbwalkSleeper[entity.Handle],
                            this.GetUnitMenu(entity),
                            this.BaseHero)
                        {
                            FailSafe = this.BaseHero.FailSafe
                        };

                        this.controllableUnits.Add(d);
                    }
                    else
                    {
                        var c = new ControllableUnit(
                            entity,
                            this.abilitySleeper,
                            this.orbwalkSleeper[entity.Handle],
                            this.GetUnitMenu(entity))
                        {
                            FailSafe = this.BaseHero.FailSafe
                        };

                        this.controllableUnits.Add(c);
                    }

                    return;
                }

                var ac = (ControllableUnit)Activator.CreateInstance(
                    type,
                    entity,
                    this.abilitySleeper,
                    this.orbwalkSleeper[entity.Handle],
                    this.GetUnitMenu(entity));
                ac.FailSafe = this.BaseHero.FailSafe;

                this.controllableUnits.Add(ac);
            }
            catch (Exception e)
            {
                Logger.Error(e);
            }
        }