Inheritance: MonoBehaviour
 public Entity AddMove(float newSpeed, float newMaxSpeed)
 {
     var component = new MoveComponent();
     component.speed = newSpeed;
     component.maxSpeed = newMaxSpeed;
     return AddMove(component);
 }
        public static MoveComponent CreateComponent()
        {
            MoveComponent component = new MoveComponent();
            component.Position = Vector2.Zero;
            component.Velocity = Vector2.Zero;
            component.Acceleration = Vector2.Zero;

            return component;
        }
Example #3
0
    public virtual void Start()
    {
        invicible = true;

        explosionPrefabGo = Resources.Load("Explosion") as GameObject;
        if (isPlayer) mainCharacter = this;
        moveComponent = GetComponent<MoveComponent>();
        fireComponent = GetComponent<FireComponent>();
        aiComponent = GetComponent<AIComponent>();
    }
 public Entity ReplaceMove(int newSpeed)
 {
     MoveComponent component;
     if (hasMove) {
         WillRemoveComponent(ComponentIds.Move);
         component = move;
     } else {
         component = new MoveComponent();
     }
     component.speed = newSpeed;
     return ReplaceComponent(ComponentIds.Move, component);
 }
Example #5
0
    public override void Init()
    {
        base.Init();

        mIsAlive = true;
        if (vAnim != null)
        {
            vAnim.CrossFade("Running@loop", 0.1f, 0, 0.5f);
            //vAnim.Play("Running@loop");
        }

        vMoveCoponent = gameObject.GetComponent<MoveComponent>();
        vMoveCoponent.OnPlay();
    }
Example #6
0
	private void Awake ()
	{
		_anim = gameObject.GetComponent <Animator> ();
		_moveComponent = gameObject.GetComponent <MoveComponent> ();
		_box = gameObject.GetComponent <BoxCollider> ();

		if (!_anim) {
			Debug.Log ("Animator is null");
			return;
		}

		if (!_moveComponent) {
			Debug.Log ("MoveComponent is null");
			return;
		}
	}
Example #7
0
    //添加某一类型的组件
    public BasicComponent AddComponent(ComponentType type)
    {
        if (ExistSpecialComponent(type))
        {
            //Debug.Log("Exist same component Type" + type);
            return(GetSpecicalComponent(type));
        }
        //Debug.Log ("Add component" + type + " in " + gameObject);

        PropertyComponent property = GetComponent <PropertyComponent> ();

        switch (type)
        {
        case ComponentType.Property:
            PropertyComponent propertyComp = gameObject.AddComponent <PropertyComponent> ();
            propertyComp.Init(ComponentType.Property, this);
            m_components.Add(propertyComp);
            return(propertyComp);

        case ComponentType.Dead:
            DeadComponent deadComp = gameObject.AddComponent <DeadComponent> ();
            deadComp.Init(ComponentType.Dead, this);
            deadComp.hp = property.HP;
            m_components.Add(deadComp);

            return(deadComp);

        case ComponentType.State:
            StateComponent stateComp = gameObject.AddComponent <StateComponent> ();
            stateComp.Init(ComponentType.State, this);
            m_components.Add(stateComp);
            stateComp.m_actionPoint = property.AP;
            return(stateComp);

        case ComponentType.Ability:
            AbilityComponent abilityComp = gameObject.AddComponent <AbilityComponent> ();
            abilityComp.Init(ComponentType.Ability, this);
            m_components.Add(abilityComp);
            return(abilityComp);

        case ComponentType.Hide:
            HideComponent hideComp = gameObject.AddComponent <HideComponent> ();
            hideComp.Init(ComponentType.Hide, this);
            m_components.Add(hideComp);
            return(hideComp);

        case ComponentType.Move:
            MoveComponent moveComp = gameObject.AddComponent <MoveComponent> ();
            moveComp.Init(ComponentType.Move, this);
            m_components.Add(moveComp);
            moveComp.moveSpeed = property.moveSpd;
            moveComp.SPD       = property.SPD;
            return(moveComp);

        case ComponentType.Attack:
            AttackComponent attackComp = gameObject.AddComponent <AttackComponent> ();
            attackComp.Init(ComponentType.Attack, this);
            m_components.Add(attackComp);
            attackComp.STR = property.STR;
            return(attackComp);

        case ComponentType.Input:
            InputComponent inputComp = gameObject.AddComponent <InputComponent> ();
            inputComp.Init(ComponentType.Input, this);
            m_components.Add(inputComp);
            return(inputComp);

        case ComponentType.CheerUp:
            CheerUpComponent cheerUpComp = gameObject.AddComponent <CheerUpComponent> ();
            cheerUpComp.Init(ComponentType.CheerUp, this);
            m_components.Add(cheerUpComp);
            return(cheerUpComp);

        case ComponentType.Monitor:
            MonitorComponent monitorComp = gameObject.AddComponent <MonitorComponent> ();
            monitorComp.Init(ComponentType.Monitor, this);
            m_components.Add(monitorComp);
            monitorComp.m_SightArea = property.HRZ;
            return(monitorComp);

        case ComponentType.Knock:
            KnockComponent knockComp = gameObject.AddComponent <KnockComponent> ();
            knockComp.Init(ComponentType.Knock, this);
            m_components.Add(knockComp);
            knockComp.m_ridus = property.HRZ;
            return(knockComp);

        case ComponentType.Item:
            ItemComponent itemComp = gameObject.AddComponent <ItemComponent> ();
            itemComp.Init(ComponentType.Item, this);
            itemComp.item     = property.item;
            itemComp.numLimit = property.itemLimit;
            m_components.Add(itemComp);
            return(itemComp);

        case ComponentType.AI:
            AIComponent aiComp = gameObject.AddComponent <AIComponent> ();
            aiComp.Init(ComponentType.AI, this);
            m_components.Add(aiComp);
            return(aiComp);

        case ComponentType.UI:
            UIComponent uiComp = gameObject.AddComponent <UIComponent>();
            uiComp.Init(ComponentType.UI, this);
            m_components.Add(uiComp);
            return(uiComp);

        default:
            return(null);
        }
    }
Example #8
0
 protected void Awake()
 {
     moveComponent = GetComponent<MoveComponent>();
 }
Example #9
0
 // Start is called before the first frame update
 void Start()
 {
     moveCom = new MoveComponent(box);
 }
 void Start()
 {
     Alive = true;
     Move  = GetComponent <MoveComponent>();
     FindNextTitle();
 }
Example #11
0
 /// <summary>
 /// 移动角色
 /// </summary>
 /// <param name="TargetCellPosition">目的地单元格</param>
 public void MoveRole(Vector2Int TargetCellPosition)
 {
     MoveComponent.Move(TargetCellPosition.ToVector3Int());
 }
Example #12
0
    protected void OnCollision(Collider2D other, Identity identity, BulletComponent bulletComponent, BoxCollider2D boxCollider2D, MoveComponent move)
    {
        EntityHolder entityHolder = other.gameObject.GetComponent <EntityHolder>();

        if (entityHolder == null)
        {
            return;
        }
        Entity   otherEntity   = entityHolder.entity;
        Identity otherIdentity = otherEntity.identity;

        if (otherEntity == identity.master)
        {
            return;
        }

        if (otherIdentity.tag != "river")
        {
            move.needMove   = false;
            identity.isDead = true;
        }

        if (otherIdentity.tag == "brick" || otherIdentity.tag == "stone")
        {
            if (other.gameObject.tag == "brick")
            {
                world.entitySystem.DestroyEntity(otherEntity);
            }
        }
        else if (otherEntity != identity.master && otherEntity.lifeComponent.enable == true)
        {
            world.lifeSystem.ChangeHP(otherEntity.lifeComponent, -bulletComponent.damage);
            world.buffSystem.AddBuff(otherEntity, bulletComponent.buffName);
            Debug.Log("bullet hit:" + otherIdentity.tag);
        }

        if (identity.isDead == true)
        {
            boxCollider2D.enabled = false; // disable collider to avoid mutiple times collision.
            world.entitySystem.DestroyEntity(identity.entity);
            world.effectSystem.CreateExplosion(bulletComponent.entity.gameobjectComponent.transform.position, "small");
        }
    }
 protected virtual void Log(MoveComponent go)
 {
     //log basic command to console
     Debug.Log($"{this.Log()} executed on {go}");
 }
 public virtual void Execute(MoveComponent go)
 {
     this.Log();
 }
 public Entity AddMove(MoveComponent component)
 {
     return(AddComponent(ComponentIds.Move, component));
 }
Example #16
0
 protected override void GetComponents()
 {
     base.GetComponents();
     moveComponent = gameObject.AddComponent <MoveComponent>();
 }
Example #17
0
        public void Update(GameTime gameTime)
        {
            ComponentManager cm = ComponentManager.GetInstance();

            foreach (var entity in cm.GetComponentsOfType <PlayerControlComponent>())
            {
                PlayerControlComponent playerComp = (PlayerControlComponent)entity.Value;

                if (cm.HasEntityComponent <InventoryComponent>(entity.Key))
                {
                    InventoryComponent invenComp = cm.GetComponentForEntity <InventoryComponent>(entity.Key);

                    if (invenComp.ItemsToAdd.Count > 0)
                    {
                        foreach (int item in invenComp.ItemsToAdd)
                        {
                            AddItemToInventory(entity.Key, item);
                        }
                        invenComp.ItemsToAdd.Clear();
                    }
                    if (invenComp.ItemsToRemove.Count > 0)
                    {
                        foreach (int item in invenComp.ItemsToRemove)
                        {
                            ItemComponent itemComp = cm.GetComponentForEntity <ItemComponent>(item);
                            invenComp.Items[itemComp.InventoryPosition] = 0;
                            invenComp.AmountOfItems--;
                        }
                        invenComp.ItemsToRemove.Clear();
                    }
                    if (playerComp.Inventory.IsButtonDown())
                    {
                        if (cm.HasEntityComponent <MoveComponent>(entity.Key) && cm.HasEntityComponent <AttackComponent>(entity.Key))
                        {
                            MoveComponent   moveComp   = cm.GetComponentForEntity <MoveComponent>(entity.Key);
                            AttackComponent attackComp = cm.GetComponentForEntity <AttackComponent>(entity.Key);
                            if (invenComp.IsOpen)
                            {
                                attackComp.CanAttack = true;
                                moveComp.CanMove     = true;
                                invenComp.HeldItem   = 0;
                                invenComp.IsOpen     = false;
                            }
                            else
                            {
                                attackComp.CanAttack = false;
                                moveComp.Velocity    = new Vector2(0.0f, 0.0f);
                                moveComp.CanMove     = false;
                                invenComp.IsOpen     = true;
                            }
                        }
                    }
                    if (invenComp.IsOpen)
                    {
                        if (invenComp.selectSlotCurCooldown <= 0.0f)
                        {
                            Vector2 stickDir = playerComp.Movement.GetDirection();

                            invenComp.selectSlotCurCooldown = invenComp.SelectSlotDelay;
                            if (Math.Abs(stickDir.X) > 0.5f || Math.Abs(stickDir.Y) > 0.5f)
                            {
                                //if the stick has been pushed in a direction
                                Point direction = MoveSystem.CalcDirection(stickDir.Y, stickDir.X);
                                Point nextSlot  = invenComp.SelectedSlot + direction;

                                UpdateNextSelectedPos(ref nextSlot, invenComp.SelectedSlot);

                                if (UpdateInventoryFocus(invenComp, nextSlot))
                                {
                                    invenComp.SelectedSlot          = nextSlot;
                                    invenComp.selectSlotCurCooldown = invenComp.SelectSlotDelay;
                                }
                            }
                            //Selecting slot
                            else if (playerComp.Interact.IsButtonDown())
                            {
                                //calculate the location of the selected slot in the items array
                                int selectedArraySlot = invenComp.SelectedSlot.Y + (invenComp.ColumnsRows.X) * invenComp.SelectedSlot.X;
                                //if no item is held
                                if (invenComp.HeldItem == 0)
                                {
                                    if (invenComp.LocationInInventory == LocationInInventory.Equipment)
                                    {
                                        //Unequip equipment
                                        int equipPos = Math.Abs(invenComp.SelectedSlot.X) - 1;
                                        if (AddItemToInventory(entity.Key, invenComp.WeaponBodyHead[equipPos]))
                                        {
                                            UnEquipItemVisually(invenComp.WeaponBodyHead[equipPos], cm);
                                            invenComp.WeaponBodyHead[equipPos] = 0;
                                        }
                                    }
                                    else if (invenComp.LocationInInventory == LocationInInventory.Bagspace)
                                    {
                                        //Picked an item to hold
                                        invenComp.HeldItem = invenComp.Items[selectedArraySlot];
                                    }
                                    else if (invenComp.LocationInInventory == LocationInInventory.Stats)
                                    {
                                        StatsComponent statComp = cm.GetComponentForEntity <StatsComponent>(entity.Key);
                                        if (statComp.SpendableStats > 0)
                                        {
                                            //Increase the selected stat
                                            if (invenComp.SelectedSlot.X == -1)
                                            {
                                                //increase int
                                                statComp.AddInt += 1;
                                            }
                                            else if (invenComp.SelectedSlot.X == -2)
                                            {
                                                //increase stamina
                                                statComp.AddSta += 1;
                                            }
                                            else if (invenComp.SelectedSlot.X == -3)
                                            {
                                                //increase agility
                                                statComp.AddAgi += 1;
                                            }
                                            else if (invenComp.SelectedSlot.X == -4)
                                            {
                                                //increase strength
                                                statComp.AddStr += 1;
                                            }
                                            statComp.SpendableStats--;
                                        }
                                    }
                                    else if (invenComp.LocationInInventory == LocationInInventory.Skills)
                                    {
                                        StatsComponent statComp = cm.GetComponentForEntity <StatsComponent>(entity.Key);
                                        //Choose the skill selected if it has not already been picked and prerequisite requirements have been met
                                        if (ChooseAvailableSkill(ref invenComp, GetSelectedSkillSlot(invenComp.SelectedSlot.X, invenComp.SelectedSlot.Y)) &&
                                            statComp.SpendableStats >= 5)
                                        {
                                            statComp.SpendableStats -= 5;
                                        }
                                    }
                                }
                                else
                                {
                                    //if we do have a held item
                                    ItemComponent heldItemComp = cm.GetComponentForEntity <ItemComponent>(invenComp.HeldItem);
                                    if (invenComp.LocationInInventory == LocationInInventory.Equipment)
                                    {
                                        //if our currently selected slot is in one of the equipment slots
                                        int equipPos = Math.Abs(invenComp.SelectedSlot.X) - 1;
                                        if ((int)heldItemComp.Type == equipPos)
                                        {
                                            int equipToSwap = 0;
                                            if (invenComp.WeaponBodyHead[equipPos] != 0)
                                            {
                                                //if there is an item in the selected slot. Swap locations of the items
                                                equipToSwap = invenComp.WeaponBodyHead[equipPos];
                                                cm.GetComponentForEntity <ItemComponent>(equipToSwap).InventoryPosition = heldItemComp.InventoryPosition;
                                                UnEquipItemVisually(equipToSwap, cm);
                                                invenComp.AmountOfItems++;
                                            }
                                            invenComp.WeaponBodyHead[equipPos] = invenComp.HeldItem;
                                            invenComp.Items[heldItemComp.InventoryPosition] = equipToSwap;
                                            heldItemComp.InventoryPosition = -equipPos;
                                            invenComp.AmountOfItems--;
                                        }
                                    }
                                    else if (invenComp.LocationInInventory == LocationInInventory.Bagspace)
                                    {
                                        int itemToSwap = 0;
                                        if (invenComp.Items[selectedArraySlot] != 0)
                                        {
                                            //Swap item locations
                                            itemToSwap = invenComp.Items[selectedArraySlot];
                                            invenComp.Items[heldItemComp.InventoryPosition] = itemToSwap;
                                            cm.GetComponentForEntity <ItemComponent>(itemToSwap).InventoryPosition = heldItemComp.InventoryPosition;
                                        }
                                        invenComp.Items[selectedArraySlot] = invenComp.HeldItem;
                                        invenComp.Items[heldItemComp.InventoryPosition] = itemToSwap;
                                        heldItemComp.InventoryPosition = selectedArraySlot;
                                    }
                                    invenComp.HeldItem = 0; // no matter what action was taken, the held item should be deselected so we can choose a new one in the future
                                }
                                UpdateActualEquippedItems(ref invenComp, ref cm, entity.Key);
                            }
                            //Quick equip
                            else if (playerComp.Attack.IsButtonDown())
                            {
                                if (invenComp.LocationInInventory == LocationInInventory.Bagspace)
                                {
                                    int           selectedArraySlot = invenComp.SelectedSlot.Y + (invenComp.ColumnsRows.X) * invenComp.SelectedSlot.X;
                                    ItemComponent selectedItemComp  = cm.GetComponentForEntity <ItemComponent>(invenComp.Items[selectedArraySlot]);

                                    if (selectedItemComp != null)
                                    {
                                        if ((int)selectedItemComp.Type <= 2)
                                        {
                                            if (invenComp.HeldItem != 0)
                                            {
                                                invenComp.HeldItem = 0;
                                            }
                                            if (invenComp.WeaponBodyHead[(int)selectedItemComp.Type] == 0)
                                            {
                                                //Equip the item
                                                invenComp.WeaponBodyHead[(int)selectedItemComp.Type] = invenComp.Items[selectedArraySlot];
                                                selectedItemComp.InventoryPosition = -(int)selectedItemComp.Type - 1;
                                                invenComp.Items[selectedArraySlot] = 0;
                                                invenComp.AmountOfItems--;
                                            }
                                            else
                                            {
                                                //The spot is occupied and will be swapped
                                                int itemToMove = invenComp.WeaponBodyHead[(int)selectedItemComp.Type];
                                                invenComp.WeaponBodyHead[(int)selectedItemComp.Type] = invenComp.Items[selectedArraySlot];
                                                invenComp.Items[selectedArraySlot] = itemToMove;

                                                cm.GetComponentForEntity <ItemComponent>(itemToMove).InventoryPosition = selectedItemComp.InventoryPosition;
                                                selectedItemComp.InventoryPosition = -(int)selectedItemComp.Type - 1;
                                                UnEquipItemVisually(itemToMove, cm);
                                            }
                                        }
                                        else if (selectedItemComp.Type == ItemType.Consumable)
                                        {
                                            selectedItemComp.Use(entity.Key, selectedItemComp.InventoryPosition);
                                            invenComp.AmountOfItems--;
                                        }
                                    }
                                }
                                UpdateActualEquippedItems(ref invenComp, ref cm, entity.Key);
                            }
                            //drop selected item
                            else if (playerComp.Back.IsButtonDown())
                            {
                                if (invenComp.LocationInInventory == LocationInInventory.Bagspace)
                                {
                                    int           selectedArraySlot = invenComp.SelectedSlot.Y + (invenComp.ColumnsRows.X) * invenComp.SelectedSlot.X;
                                    ItemComponent selectedItemComp  = cm.GetComponentForEntity <ItemComponent>(invenComp.Items[selectedArraySlot]);

                                    if (selectedItemComp != null)
                                    {
                                        PositionComponent playerPosComp = cm.GetComponentForEntity <PositionComponent>(entity.Key);
                                        cm.AddComponentsToEntity(invenComp.Items[selectedArraySlot], new IComponent[] {
                                            new PositionComponent(playerPosComp.Position),
                                            new InteractComponent(InteractType.Loot)
                                        });
                                        invenComp.Items[selectedArraySlot] = 0;
                                        invenComp.AmountOfItems--;
                                    }
                                }
                            }
                            else if (cm.HasEntityComponent <ActionBarComponent>(entity.Key))
                            {
                                ActionBarComponent actionBComp = cm.GetComponentForEntity <ActionBarComponent>(entity.Key);
                                if (playerComp.ActionBar1.IsButtonDown())
                                {
                                    BindToActionBar(ref invenComp, ref actionBComp, ref cm, 0);
                                }
                                else if (playerComp.ActionBar2.IsButtonDown())
                                {
                                    BindToActionBar(ref invenComp, ref actionBComp, ref cm, 1);
                                }
                                else if (playerComp.ActionBar3.IsButtonDown())
                                {
                                    BindToActionBar(ref invenComp, ref actionBComp, ref cm, 2);
                                }
                                else if (playerComp.ActionBar4.IsButtonDown())
                                {
                                    BindToActionBar(ref invenComp, ref actionBComp, ref cm, 3);
                                }
                                else
                                {
                                    invenComp.selectSlotCurCooldown = 0.0f;
                                }
                            }
                            else
                            {
                                invenComp.selectSlotCurCooldown = 0.0f;
                            }
                        }
                        else
                        {
                            invenComp.selectSlotCurCooldown -= (float)gameTime.ElapsedGameTime.TotalSeconds;
                        }
                    }
                }
            }
        }
Example #18
0
    protected void HandleStandardInput()
    {
        if (UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject())
        {
            return;
        }

        if (Input.GetMouseButtonDown(0))
        {
            StartDrag();
        }
        if (Input.GetMouseButton(0))
        {
            dragTimer += Time.deltaTime;

            RaycastHit hit = RaycastToGround();

            dragEndPos = hit.point;

            Vector3 midPoint = (dragStartPos + dragEndPos) / 2;
            Vector3 extents  = new Vector3(Mathf.Abs((dragStartPos - midPoint).x), Mathf.Abs((dragStartPos - midPoint).y), Mathf.Abs((dragStartPos - midPoint).z)) * 2;

            selectionImage.transform.position = midPoint;
            selectionImage.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, extents.x);
            selectionImage.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, extents.z);
        }
        if (Input.GetMouseButtonUp(0))
        {
            //if (dragTimer < 0.1f) {
            //    selectionImage.enabled = false;

            //    foreach (SelectableComponent selectedObject in selectedObjects) {
            //        if (selectedObject != null) {
            //            //selectedObject.GetComponentInChildren<Renderer>().material.color = Color.white;
            //            selectedObject.Deselect();
            //        }
            //    }
            //    selectedObjects.Clear();
            //    dragTimer = 0;

            //    //ClickableComponent[] clickableComponents = RaycastForClickableComponents();
            //    //if (clickableComponents != null && clickableComponents.Length > 0)
            //    //    ClickableComponentManager.instance.UnclickAllClickableComponents();
            //    //foreach (ClickableComponent clickableComponent in clickableComponents) {
            //    //    clickableComponent.Click();
            //    //}

            //    return;
            //}
            dragTimer = 0;

            EndDrag();
        }
        if (Input.GetMouseButtonDown(1))
        {
            RaycastHit hit = RaycastToGround();

            dragStartPos = hit.point;

            foreach (SelectableComponent selectedObject in selectedObjects)
            {
                MoveComponent mc = selectedObject.GetComponent <MoveComponent>();
                if (mc != null)
                {
                    //mc.GetComponent<UnityEngine.AI.NavMeshAgent>().destination = hit.point;
                    mc.SetAgentDestination(hit.point);
                }
            }
        }
    }
Example #19
0
 // Use this for initialization
 protected virtual void Start()
 {
     move = GetComponent <MoveComponent>();
 }
Example #20
0
    private void LoadData(List <string> data, bool isHeroSkill)
    {
        for (int i = 1; i < data.Count; i++)
        {
            switch (data[i])
            {
            case ".id":
                Id = data[++i];
                break;

            case ".level":
                Level = int.Parse(data[++i]);
                break;

            case ".type":
                Type = data[++i];
                break;

            case ".atk":
                Accuracy = float.Parse(data[++i]) / 100;
                break;

            case ".dmg":
                if (isHeroSkill)
                {
                    DamageMod = float.Parse(data[++i]) / 100;
                }
                else
                {
                    DamageMin = float.Parse(data[++i]);
                    DamageMax = float.Parse(data[++i]);
                }
                break;

            case ".crit":
                CritMod = float.Parse(data[++i]) / 100;
                break;

            case ".launch":
                LaunchRanks = new FormationSet(data[++i]);
                break;

            case ".target":
                if (++i < data.Count && data[i--][0] != '.')
                {
                    TargetRanks = new FormationSet(data[++i]);
                }
                else
                {
                    TargetRanks = new FormationSet("");
                }
                break;

            case ".is_crit_valid":
                IsCritValid = bool.Parse(data[++i].ToLower());
                break;

            case ".self_target_valid":
                IsSelfValid = bool.Parse(data[++i].ToLower());
                break;

            case ".extra_targets_count":
                ++i;
                break;

            case ".extra_targets_chance":
                ExtraTargetsChance = float.Parse(data[++i]);
                break;

            case ".is_user_selected_targets":
                ++i;
                break;

            case ".can_miss":
                CanMiss = bool.Parse(data[++i].ToLower());
                break;

            case ".is_continue_turn":
                IsContinueTurn = bool.Parse(data[++i].ToLower());
                break;

            case ".per_turn_limit":
                LimitPerTurn = int.Parse(data[++i]);
                break;

            case ".per_battle_limit":
                LimitPerBattle = int.Parse(data[++i]);
                break;

            case ".valid_modes":
                while (++i < data.Count && data[i--][0] != '.')
                {
                    if (data[++i].Length < 2)
                    {
                        continue;
                    }

                    ValidModes.Add(data[i]);
                }
                break;

            case ".human_effects":
                var humanEffects = new List <Effect>();
                ModeEffects.Add("human", humanEffects);
                while (++i < data.Count && data[i--][0] != '.')
                {
                    if (data[++i].Length < 2)
                    {
                        continue;
                    }

                    if (DarkestDungeonManager.Data.Effects.ContainsKey(data[i]))
                    {
                        humanEffects.Add(DarkestDungeonManager.Data.Effects[data[i]]);
                    }
                    else
                    {
                        Debug.LogError("Missing effect " + data[i] + " in skill " + Id);
                    }
                }
                break;

            case ".beast_effects":
                var beastEffects = new List <Effect>();
                ModeEffects.Add("beast", beastEffects);
                while (++i < data.Count && data[i--][0] != '.')
                {
                    if (data[++i].Length < 2)
                    {
                        continue;
                    }

                    if (DarkestDungeonManager.Data.Effects.ContainsKey(data[i]))
                    {
                        beastEffects.Add(DarkestDungeonManager.Data.Effects[data[i]]);
                    }
                    else
                    {
                        Debug.LogError("Missing effect " + data[i] + " in skill " + Id);
                    }
                }
                break;

            case ".effect":
                while (++i < data.Count && data[i--][0] != '.')
                {
                    if (data[++i].Length < 2)
                    {
                        continue;
                    }

                    if (DarkestDungeonManager.Data.Effects.ContainsKey(data[i]))
                    {
                        Effects.Add(DarkestDungeonManager.Data.Effects[data[i]]);
                    }
                    else
                    {
                        Debug.LogError("Missing effect " + data[i] + " in skill " + Id);
                    }
                }
                break;

            case ".generation_guaranteed":
                IsGenerationGuaranteed = bool.Parse(data[++i].ToLower());
                break;

            case ".is_knowledgeable":
                IsKnowledgeable = bool.Parse(data[++i].ToLower());
                break;

            case ".heal":
                Heal = new HealComponent(int.Parse(data[++i]), int.Parse(data[++i]));
                break;

            case ".move":
                Move = new MoveComponent(int.Parse(data[++i]), int.Parse(data[++i]));
                break;

            case "combat_skill:":
                break;

            default:
                Debug.LogError("Unexpected token in combat skill: " + data[i]);
                break;
            }
        }
        if (Accuracy == 0 || TargetRanks.IsSelfFormation || TargetRanks.IsSelfTarget)
        {
            if (Heal == null)
            {
                Category = SkillCategory.Support;
            }
            else
            {
                Category = SkillCategory.Heal;
            }
        }
    }
 void AssignComponents()
 {
     playerRB      = GetComponent <Rigidbody2D>();
     moveComponent = new MoveComponent();
 }
Example #22
0
 void Update()
 {
     MoveComponent.Update();
 }
Example #23
0
    protected void OnCollision(Collider2D other, Identity identity, BulletComponent bulletComponent, Animator animator, BoxCollider2D boxCollider2D, MoveComponent move)
    {
        Entity   otherEntity   = other.gameObject.GetComponent <EntityHolder>().entity;
        Identity otherIdentity = otherEntity.identity;

        if (otherIdentity.tag == "brick" || otherIdentity.tag == "stone")
        {
            //identity.isDead = true;
            if (other.gameObject.tag == "brick")
            {
                world.entitySystem.DestroyEntity(otherEntity);
            }
        }
        else if (otherEntity != identity.master && otherIdentity.tag == "tank")
        {
            //identity.isDead = true;
            //other.gameObject.GetComponent<Life>().ChangeHP(-bulletComponent.damage);
            world.buffSystem.AddBuff(otherEntity, bulletComponent.buffName);
            Debug.Log("bullet hit tank");
        }

        if (otherIdentity.tag != "river")
        {
            move.needMove   = false;
            identity.isDead = true;
        }

        if (identity.isDead == true)
        {
            animator.SetBool("destroy", true);
            boxCollider2D.enabled = false; // disable collider to avoid mutiple times collision.
        }
    }
Example #24
0
 public void MoveRole(Vector2Int[] moveList)
 {
     MoveComponent.Move(moveList.ToList());
 }
Example #25
0
        private void Kick(MoveComponent component)
        {
            var view = component.gameObject.GetComponentInParent <PhotonView>();

            KickPlayer?.Invoke(view, component);
        }
    List <CreatPostionInfo> GetCreatePostionInfos(SkillDataGenerate skillData, EntityBase skiller, int Length)
    {
        MoveComponent   mc = skiller.GetComp <MoveComponent>();
        PlayerComponent pc = skiller.GetComp <PlayerComponent>();

        List <CreatPostionInfo> result = new List <CreatPostionInfo>();

        result.Clear();

        if (Length == 0)
        {
            return(result);
        }

        HardPointEnum l_FXCreatPoint = skillData.m_FlyCreatPoint;

        Vector3 forward = pc.faceDir.ToVector();
        Vector3 dir     = forward;
        Vector3 pos     = Vector3.zero;

        //获取散射区域
        Area skillArea = UpdatSkillArea(areaCache, skillData, skiller, null);

        //TODO 寻敌方法
        //CharacterBase enemy = GetRecentlyEnemy(skillArea, skiller.m_camp, false);
        //CharacterBase enemy = null;
        MoveComponent emc = null;

        if (l_FXCreatPoint != HardPointEnum.enemy)
        {
            pos = mc.pos.ToVector();
        }
        else
        {
            if (emc == null)
            {
                return(result);
            }
            else
            {
                pos = emc.pos.ToVector();
            }
        }

        Vector3 leftBorder    = Vector3.zero;
        Vector3 leftDir       = Vector3.zero;
        Vector3 leftPos       = Vector3.zero;
        float   sectorStep    = 0;
        float   rectangleStep = 0;

        AreaDataGenerate area = DataGenerateManager <AreaDataGenerate> .GetData(skillData.m_FlyObjectArea);

        switch (area.m_SkewDirection)
        {
        case DirectionEnum.Forward: break;

        case DirectionEnum.Backward: forward *= -1; break;

        case DirectionEnum.Close: forward = (emc.pos.ToVector() - mc.pos.ToVector()).normalized; break;

        case DirectionEnum.Leave: forward = (mc.pos.ToVector() - emc.pos.ToVector()).normalized; break;
        }

        switch (area.m_Shape)
        {
        case AreaType.Circle:
            leftBorder = forward.Vector3RotateInXZ(360 * 0.5f);
            sectorStep = 360 / (Length + 1);
            break;

        case AreaType.Sector:
            leftBorder = forward.Vector3RotateInXZ(area.m_Angle * 0.5f);
            sectorStep = area.m_Angle / (Length + 1);
            break;

        case AreaType.Rectangle:
            leftDir       = forward.Vector3RotateInXZ(90);
            leftPos       = pos + leftDir * area.m_Width * 0.5f;
            rectangleStep = area.m_Width / (Length + 1);
            break;
        }

        for (int i = 0; i < Length; i++)
        {
            switch (area.m_Shape)
            {
            case AreaType.Circle:
            case AreaType.Sector:
                dir = leftBorder.Vector3RotateInXZ2((i + 1) * sectorStep);
                pos = pos + forward * area.m_SkewDistance;
                break;

            case AreaType.Rectangle:
                pos = leftPos - leftDir * rectangleStep * (i + 1);
                break;
            }


            CreatPostionInfo cpi = new CreatPostionInfo();
            cpi.m_pos = pos;
            cpi.m_dir = dir;

            result.Add(cpi);
        }

        return(result);
    }
Example #27
0
 public void Run()
 {
     foreach (var index in filter)
     {
         ref MoveComponent      moveComponent      = ref filter.Get1(index);
         ref RigidbodyComponent rigidbodyComponent = ref filter.Get2(index);
Example #28
0
        public void Update(GameTime gameTime)
        {
            ComponentManager cm = ComponentManager.GetInstance();
            List <Tuple <int, PositionComponent> > players = new List <Tuple <int, PositionComponent> >();

            foreach (var player in cm.GetComponentsOfType <PlayerComponent>())
            {
                players.Add(new Tuple <int, PositionComponent>(player.Key, cm.GetComponentForEntity <PositionComponent>(player.Key)));
            }

            foreach (var entity in cm.GetComponentsOfType <AttackComponent>())
            {
                if (cm.HasEntityComponent <AIComponent>(entity.Key) && cm.HasEntityComponent <PositionComponent>(entity.Key))
                {
                    AIComponent       ai      = cm.GetComponentForEntity <AIComponent>(entity.Key);
                    PositionComponent posComp = cm.GetComponentForEntity <PositionComponent>(entity.Key);

                    //find closest target
                    int   closestEntity = 0;
                    float closestDist   = float.MaxValue;

                    for (int i = 0; i < players.Count; i++)
                    {
                        float dist = Vector2.Distance(players[i].Item2.Position, posComp.Position);
                        if (dist < ai.DetectRange && dist < closestDist)
                        {
                            closestEntity = players[i].Item1;
                            closestDist   = dist;
                        }
                    }

                    if (closestEntity != 0)
                    {
                        ai.TargetEntity = closestEntity;
                    }
                    else
                    {
                        ai.TargetEntity = 0;
                    }

                    // Do some check here: cm.HasEntity....<movecomp> / <attackcomp> ?
                    MoveComponent   moveComp        = cm.GetComponentForEntity <MoveComponent>(entity.Key);
                    AttackComponent attackComponent = cm.GetComponentForEntity <AttackComponent>(entity.Key);
                    if (ai.TargetEntity != 0)
                    {
                        Vector2            pointToTarget, pointToTCompare;
                        Point              nextDir;
                        PositionComponent  posOftarget     = cm.GetComponentForEntity <PositionComponent>(ai.TargetEntity);
                        CollisionComponent collComp        = cm.GetComponentForEntity <CollisionComponent>(entity.Key);
                        Vector2            unNormalizedDir = new Vector2(posOftarget.Position.X - posComp.Position.X, posOftarget.Position.Y - posComp.Position.Y);
                        float              distance        = (float)Math.Sqrt(unNormalizedDir.X * unNormalizedDir.X + unNormalizedDir.Y * unNormalizedDir.Y);
                        Vector2            direction       = new Vector2(unNormalizedDir.X / distance, unNormalizedDir.Y / distance);

                        nextDir         = MoveSystem.CalcDirection(direction.X, direction.Y);
                        pointToTarget   = posOftarget.Position + new Vector2(-nextDir.X * (collComp.CollisionBox.Width), -nextDir.Y * (collComp.CollisionBox.Height));
                        pointToTCompare = posComp.Position + new Vector2(nextDir.X * (collComp.CollisionBox.Width), nextDir.Y * (collComp.CollisionBox.Height));
                        ai.Destination  = pointToTarget.ToPoint();

                        if (attackComponent.AttackCooldown <= 0.0f &&
                            Vector2.Distance(posComp.Position, pointToTarget) <= (collComp.CollisionBox.Width * Math.Abs(nextDir.X) + collComp.CollisionBox.Height * Math.Abs(nextDir.Y)) / 2 &&
                            !cm.GetComponentForEntity <KnockbackComponent>(entity.Key).KnockbackActive)
                        {
                            moveComp.Direction             = nextDir;
                            moveComp.CanMove               = false;
                            attackComponent.AttackCooldown = attackComponent.RateOfFire;
                            attackComponent.IsAttacking    = true;
                            cm.GetComponentForEntity <SoundComponent>(entity.Key).Sounds["Attack"].Action = SoundAction.Play;
                            if (cm.HasEntityComponent <AnimationGroupComponent>(entity.Key))
                            {
                                AnimationGroupComponent animGroupComp = cm.GetComponentForEntity <AnimationGroupComponent>(entity.Key);
                                int anim = GetAnimationRow(moveComp.Direction) + 8;
                                if (animGroupComp.ActiveAnimation != anim)
                                {
                                    animGroupComp.ActiveAnimation = anim;
                                }
                            }
                        }
                    }
                    if (attackComponent.AttackCooldown > 0.0f)
                    {
                        attackComponent.AttackCooldown -= (float)gameTime.ElapsedGameTime.TotalSeconds;
                    }
                    else
                    {
                        moveComp.CanMove = true;
                    }
                }
            }
        }
Example #29
0
 public void HeadChange(MoveComponent head)
 {
     _head = head;
 }
Example #30
0
 public SetDestination(MoveComponent moveComponent)
 {
     this.moveComponent = moveComponent;
 }
Example #31
0
        public void Run()
        {
            foreach (int i in _moveEntities)
            {
                PositionComponent positionComponent = _moveEntities.Get1[i];
                MoveComponent     moveComponent     = _moveEntities.Get2[i];
                Transform         transform         = _moveEntities.Get3[i].Transform;
                EcsEntity         movingEntity      = _moveEntities.Entities[i];

                Vector3 curPosition     = transform.position;
                float   height          = curPosition.y;
                Vector3 desiredPosition = moveComponent.DesiredPosition.ToVector3(height);
                Vector3 estimatedVector = desiredPosition - curPosition;
                if (estimatedVector.magnitude > Epsilon)
                {
                    transform.position = Vector3.Lerp(
                        transform.position, desiredPosition,
                        moveComponent.Speed / estimatedVector.magnitude * Time.deltaTime);
                    continue;
                }

                Vector2Int oldPosition = positionComponent.Position;
                Vector2Int newPosition = moveComponent.DesiredPosition;
                if (!oldPosition.Equals(newPosition))
                {
                    movingEntity.Set <NewPositionComponent>().NewPosition = newPosition;
                }

                Vector2Int newDesiredPosition;
                Vector3    newDirection;
                switch (moveComponent.Heading)
                {
                case Directions.Up:
                    newDesiredPosition = new Vector2Int(newPosition.x, newPosition.y + 1);
                    newDirection       = new Vector3(0, 0, 0);
                    break;

                case Directions.Right:
                    newDesiredPosition = new Vector2Int(newPosition.x + 1, newPosition.y);
                    newDirection       = new Vector3(0, 90, 0);
                    break;

                case Directions.Down:
                    newDesiredPosition = new Vector2Int(newPosition.x, newPosition.y - 1);
                    newDirection       = new Vector3(0, 180, 0);
                    break;

                case Directions.Left:
                    newDesiredPosition = new Vector2Int(newPosition.x - 1, newPosition.y);
                    newDirection       = new Vector3(0, -90, 0);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                transform.rotation = Quaternion.Euler(newDirection);

                bool stuckToWall = false;
                foreach (EcsEntity entity in _worldService.WorldField[newDesiredPosition.x][newDesiredPosition.y])
                {
                    if (!entity.IsAlive())
                    {
                        continue;
                    }
                    if (entity.Get <WallComponent>() == null)
                    {
                        continue;
                    }

                    stuckToWall = true;
                }

                if (stuckToWall)
                {
                    movingEntity.Set <StoppedComponent>();
                }
                else
                {
                    moveComponent.DesiredPosition = newDesiredPosition;
                    movingEntity.Unset <StoppedComponent>();
                }
            }
        }
 public Entity AddMove(int newSpeed)
 {
     var component = new MoveComponent();
     component.speed = newSpeed;
     return AddMove(component);
 }
 public override void Execute(MoveComponent go)
 {
     go.MoveUp();
     base.Execute(go);
 }
Example #34
0
 //Asigno variables
 private void Awake()
 {
     _follow   = false;
     _steering = new Pursit(transform, PursitTarget, TargetRb, TimePrediction);
     _move     = new MoveComponent(GetComponent <Rigidbody>(), transform, 5f);
 }
Example #35
0
    public void PlayerJoin(EntityBase entity)
    {
        ConnectionComponent connectComp = entity.GetComp <ConnectionComponent>();
        PlayerComponent     playerComp  = null;

        if (!entity.GetExistComp <PlayerComponent>())
        {
            playerComp = new PlayerComponent();
            entity.AddComp(playerComp);
        }
        else
        {
            playerComp = entity.GetComp <PlayerComponent>();
        }

        //将角色ID传入游戏
        playerComp.characterID = connectComp.m_session.player.characterID;
        playerComp.nickName    = connectComp.m_session.player.nickName;

        Debug.Log("characterID ->" + playerComp.characterID + "<-");

        if (playerComp.characterID == "" ||
            playerComp.characterID == null)
        {
            playerComp.characterID = "1";
        }

        ElementData e1 = new ElementData();

        e1.id  = 100;
        e1.num = 10;
        playerComp.elementData.Add(e1);

        ElementData e2 = new ElementData();

        e2.id  = 101;
        e2.num = 10;
        playerComp.elementData.Add(e2);

        ElementData e3 = new ElementData();

        e3.id  = 102;
        e3.num = 10;
        playerComp.elementData.Add(e3);

        ElementData e4 = new ElementData();

        e4.id  = 103;
        e4.num = 00;
        playerComp.elementData.Add(e4);

        if (!entity.GetExistComp <CommandComponent>())
        {
            CommandComponent c = new CommandComponent();
            entity.AddComp(c);
        }

        if (!entity.GetExistComp <TransfromComponent>())
        {
            TransfromComponent c = new TransfromComponent();
            c.pos.FromVector(new Vector3(15, 0, 0));
            entity.AddComp(c);
        }

        if (!entity.GetExistComp <AssetComponent>())
        {
            AssetComponent c = new AssetComponent();
            c.m_assetName = playerComp.CharacterData.m_ModelID;
            entity.AddComp(c);
        }

        if (!entity.GetExistComp <MoveComponent>())
        {
            MoveComponent c = new MoveComponent();
            c.pos.FromVector(new Vector3(15, 0, 0));

            entity.AddComp(c);
        }


        if (!entity.GetExistComp <SkillStatusComponent>())
        {
            SkillStatusComponent c = new SkillStatusComponent();

            DataTable data = DataManager.GetData("SkillData");
            for (int i = 0; i < data.TableIDs.Count; i++)
            {
                c.m_skillList.Add(new SkillData(data.TableIDs[i], i));
                c.m_CDList.Add(0);
            }
            entity.AddComp(c);
        }

        if (!entity.GetExistComp <CDComponent>())
        {
            CDComponent c = new CDComponent();
            entity.AddComp(c);
        }

        if (!entity.GetExistComp <CampComponent>())
        {
            CampComponent c = new CampComponent();
            c.creater = entity.ID;
            entity.AddComp(c);
        }

        if (!entity.GetExistComp <MoveComponent>())
        {
            MoveComponent c = new MoveComponent();
            entity.AddComp(c);
        }

        if (!entity.GetExistComp <CollisionComponent>())
        {
            CollisionComponent c = new CollisionComponent();
            c.area.areaType = AreaType.Circle;
            c.area.radius   = playerComp.CharacterData.m_Radius;
            entity.AddComp(c);
        }

        if (!entity.GetExistComp <LifeComponent>())
        {
            LifeComponent c = new LifeComponent();
            c.maxLife = playerComp.CharacterData.m_hp;
            c.life    = playerComp.CharacterData.m_hp;
            entity.AddComp(c);
        }

        if (!entity.GetExistComp <BlowFlyComponent>())
        {
            BlowFlyComponent c = new BlowFlyComponent();
            entity.AddComp(c);
        }

        //预测一个输入
        //TODO 放在框架中
        if (entity.GetExistComp <ConnectionComponent>())
        {
            ConnectionComponent cc = entity.GetComp <ConnectionComponent>();
            cc.m_lastInputCache = new CommandComponent();
            cc.m_defaultInput   = new CommandComponent();
        }

        GameTimeComponent gtc = m_world.GetSingletonComp <GameTimeComponent>();

        gtc.GameTime = 50 * 60 * 1000;
    }
 public Entity AddMove(MoveComponent component)
 {
     return AddComponent(ComponentIds.Move, component);
 }
Example #37
0
        //Update stats according to the history (if player died)
        private void UpdateEntityStatsFromHistory(int entity)
        {
            ComponentManager cm      = ComponentManager.GetInstance();
            StatsComponent   comp    = cm.GetComponentForEntity <StatsComponent>(entity);
            LevelComponent   lvlComp = cm.GetComponentForEntity <LevelComponent>(entity);

            while (comp.RemoveStats > 0)
            {
                if (lvlComp.CurrentLevel <= 0)
                {
                    break;
                }

                if (comp.SpendableStats > 0)
                {
                    comp.SpendableStats -= 1;
                    comp.RemoveStats    -= 1;
                }
                else
                {
                    if (comp.StatHistory.Length >= 3)
                    {
                        int    start = comp.StatHistory.Length - 3;
                        string stat  = comp.StatHistory.Substring(start);
                        switch (stat)
                        {
                        case "str":
                            if (cm.HasEntityComponent <AttackComponent>(entity) && cm.HasEntityComponent <HealthComponent>(entity))
                            {
                                AttackComponent attackComp = cm.GetComponentForEntity <AttackComponent>(entity);
                                HealthComponent healthComp = cm.GetComponentForEntity <HealthComponent>(entity);
                                attackComp.Damage  = attackComp.Damage - 2;
                                healthComp.Max     = healthComp.Max - 1;
                                healthComp.Current = healthComp.Current - 1;
                                comp.Strength     -= 1;
                            }
                            break;

                        case "agi":
                            if (cm.HasEntityComponent <MoveComponent>(entity) && cm.HasEntityComponent <AttackComponent>(entity))
                            {
                                MoveComponent   moveComp   = cm.GetComponentForEntity <MoveComponent>(entity);
                                AttackComponent attackComp = cm.GetComponentForEntity <AttackComponent>(entity);
                                attackComp.RateOfFire = attackComp.RateOfFire - 0.05f;
                                moveComp.Speed        = moveComp.Speed - 0.03f;
                                comp.Agility         -= 1;
                            }
                            break;

                        case "sta":
                            if (cm.HasEntityComponent <HealthComponent>(entity))
                            {
                                HealthComponent healthComp = cm.GetComponentForEntity <HealthComponent>(entity);
                                healthComp.Max     = healthComp.Max - 2;
                                healthComp.Current = healthComp.Current - 2;
                                comp.Stamina      -= 1;
                            }
                            break;

                        case "int":
                            if (cm.HasEntityComponent <EnergyComponent>(entity))
                            {
                                EnergyComponent energyComp = cm.GetComponentForEntity <EnergyComponent>(entity);
                                energyComp.Max  = energyComp.Max - 2;
                                comp.Intellect -= 1;
                            }
                            break;
                        }
                        comp.StatHistory  = comp.StatHistory.Substring(0, comp.StatHistory.Length - 3);
                        comp.RemoveStats -= 1;
                    }
                }
            }
        }
Example #38
0
 void Start()
 {
     _agent = gameObject.GetComponent <MoveComponent>();
 }
Example #39
0
    public override void FixedUpdate(int deltaTime)
    {
        clist.Clear();

        List <EntityBase> list = GetEntityList();

        for (int i = 0; i < list.Count; i++)
        {
            CollisionComponent acc = (CollisionComponent)list[i].GetComp("CollisionComponent");
            acc.CollisionList.Clear();

            clist.Add(acc);
        }

        //string content = "";

        for (int i = 0; i < clist.Count; i++)
        {
            CollisionComponent acc = clist[i];

            BlockComponent abc = null;

            if (list[i].GetExistComp("BlockComponent"))
            {
                abc = (BlockComponent)list[i].GetComp("BlockComponent");
            }

            if (list[i].GetExistComp("MoveComponent"))
            {
                MoveComponent amc = (MoveComponent)list[i].GetComp("MoveComponent");

                acc.area.position  = amc.pos.ToVector();
                acc.area.direction = amc.dir.ToVector();
            }

            for (int j = i + 1; j < list.Count; j++)
            {
                CollisionComponent bcc = clist[j];

                //两个阻挡组件之间不计算阻挡
                if (abc != null && list[j].GetExistComp("BlockComponent"))
                {
                    continue;
                }

                if (list[j].GetExistComp("MoveComponent"))
                {
                    MoveComponent bmc = (MoveComponent)list[j].GetComp("MoveComponent");

                    bcc.area.position  = bmc.pos.ToVector();
                    bcc.area.direction = bmc.dir.ToVector();
                }

                if (acc.area.AreaCollideSucceed(bcc.area))
                {
                    acc.CollisionList.Add(bcc.Entity);
                    bcc.CollisionList.Add(acc.Entity);
                }
            }
        }
    }