Inheritance: MonoBehaviour
Example #1
0
    void Start()
    {
        //Инициализация
        anim = GetComponent <Animation>();
        rig  = GetComponent <Rigidbody>();
        VARS = GetComponent <PlayerVars>();

        rig.isKinematic = !GetComponent <NetworkView>().isMine;

        //Дабы не случилось форсмажоров
        transform.position = new Vector3(transform.position.x, 51.4f, transform.position.z);

        Physics.IgnoreLayerCollision(10, 10, true);
        Physics.IgnoreLayerCollision(10, 11, true);

        charS = CharS.Idle;

        damage_timer = Time.time;

        //PATHFINDING
        self = GetComponent <RTSObject>();
        UpdateCurrentTile();

        DontDestroyOnLoad(this);
    }
 public MouseEventArgs(int x, int y, int button, RTSObject target)
 {
     this.X = x;
     this.Y = y;
     this.button = button;
     this.target = target;
 }
Example #3
0
 public MouseEventArgs(int x, int y, int button, RTSObject target)
 {
     this.X      = x;
     this.Y      = y;
     this.button = button;
     this.target = target;
 }
Example #4
0
 // funcion que controla el ataque
 public void Attack()
 {
     if (enlace.GetComponent<Player>().objetivos.Count > 0) {
         targetlocal = (RTSObject)enlace.GetComponent<Player>().objetivos[0];
         if (targetlocal != null) {
             transform.LookAt(targetlocal.transform);
             GetComponent<MovimientoAleatorioCivil>().enabled = false; // desactivo el movimiento aleatorio
             dist = Vector3.Distance(transform.position, targetlocal.transform.position);
             if (targetlocal.GetComponent<RTSObject>().hitPoints == 0)
             {
                 enlace.GetComponent<Player>().objetivos.Remove(targetlocal);
             }
             if (dist > 2)
             {
                 transform.Translate(0, 0, 1 * speed * Time.deltaTime);
                 anim.SetBool("IsWalking", true);
             }
             else
             {
                 transform.Translate(0, 0, 0);
                 anim.SetBool("IsWalking", false);
                 GetComponent<RTSObject>().AttackObject(targetlocal);
             }
         }
     }
 }
Example #5
0
    public float GetResourceAmount(RTSObject.ResourceType resourceType)
    {
        if (!resourceAmounts.ContainsKey(resourceType))
            throw new ArgumentOutOfRangeException("resourceType");

        return resourceAmounts[resourceType];
    }
 public Order(string name, int orderType, RTSObject target)
 {
     Name = name;
     OrderType = orderType;
     OrderLocation = target.transform.position;
     Target = target;
 }
Example #7
0
 public Order(string name, int orderType, RTSObject target)
 {
     Name          = name;
     OrderType     = orderType;
     OrderLocation = target.transform.position;
     Target        = target;
 }
Example #8
0
 private void ShellingAttack(RTSObject enemyRtsObject, float dist, float damage, float radius)
 {
     if (dist <= radius && enemyRtsObject.side != Faction.Player)
     {
         enemyRtsObject.Attacked(damage);
     }
 }
Example #9
0
 public GetPathThread(RTSObject objectCalling, Cell currentTile, Vector3 targetTile, int blockingLevel, CallBackDelegate callBackFunction = null)
 {
     m_ObjectCalling    = objectCalling;
     m_CurrentTile      = currentTile;
     m_TargetTile       = targetTile;
     m_BlockingLevel    = blockingLevel;
     m_CallBackFunction = callBackFunction;
 }
 public GetPathThread(RTSObject objectCalling, Tile currentTile, Tile targetTile, int blockingLevel, CallBackDelegate callBackFunction = null)
 {
     m_ObjectCalling = objectCalling;
     m_CurrentTile = currentTile;
     m_TargetTile = targetTile;
     m_BlockingLevel = blockingLevel;
     m_CallBackFunction = callBackFunction;
 }
Example #11
0
 public void DeselectObject(RTSObject obj)
 {
     if (obj is IOrderable)
     {
         SelectedActiveObjects.Remove((IOrderable)obj);
     }
     obj.SetDeselected();
     SelectedObjects.Remove(obj);
 }
Example #12
0
    void Start()
    {
        slider.gameObject.SetActive(true);
        hpText.gameObject.SetActive(true);
        RTSObject rtsObject = GetComponent <RTSObject>();

        maxHP = rtsObject.maxHP;
        OnHPCahnged(maxHP);
        rtsObject.enemyAttack += OnHPCahnged;
    }
Example #13
0
 public void AddObject(RTSObject obj)
 {
     if (!SelectedObjects.Contains(obj))
     {
         if (obj is IOrderable && obj.gameObject.layer == 8)
         {
             SelectedActiveObjects.Add((IOrderable)obj);
         }
         SelectedObjects.Add(obj);
         obj.SetSelected();
     }
 }
 public void AddObject(RTSObject obj)
 {
     if (!SelectedObjects.Contains (obj))
     {
         if (obj is IOrderable && obj.gameObject.layer == primaryPlayer.controlledLayer)
         {
             SelectedActiveObjects.Add ((IOrderable)obj);
         }
         SelectedObjects.Add (obj);
         obj.SetSelected ();
     }
 }
Example #15
0
    /// <summary>
    /// Get the HUD sprite corresponding the given resource.
    /// </summary>
    /// <param name="resourceType">The type of the resource to get.</param>
    /// <returns>HUD resource sprite corresponding to the given resource type.</returns>
    protected Sprite GetResourceSprite(RTSObject.ResourceType resourceType)
    {
        // Lazily load the resource sprites.
        if (resourceSprites == null)
        {
            resourceSprites = new Dictionary<RTSObject.ResourceType, Sprite>();
            resourceSprites[RTSObject.ResourceType.Gold] = Resources.Load<Sprite>("HUD/Resource/GoldIcon");
            resourceSprites[RTSObject.ResourceType.Food] = Resources.Load<Sprite>("HUD/Resource/FoodIcon");
            resourceSprites[RTSObject.ResourceType.Wood] = Resources.Load<Sprite>("HUD/Resource/WoodIcon");
        }

        return resourceSprites[resourceType];
    }
Example #16
0
    void CollisionAttackOrResponse(AttackObject unit, RTSObject enemy, float dist)
    {
        if (unit.side != enemy.side)
        {
            if (dist <= unit.attack.attackRadius + enemy.SoftRadius)
            {
                unit.Attack(enemy);
            }
        }

        if (dist > unit.attack.attackRadius + enemy.SoftRadius && unit.attack.IsAttack && enemy == unit.attack.Enemy)
        {
            unit.EnemyOut();
        }
    }
Example #17
0
    /// <summary>
    /// Changes the currently selected RTS element for the current player, or unselects it.
    /// </summary>
    /// <param name="newSelection">The new RTS element to select, or null to unselect any element.</param>
    internal void ChangeSelectedRtsObject(RTSObject newSelection)
    {
        if (newSelection != SelectedObject)
        {
            if (SelectedObject != null)
            {
                OnSelectionEnd(SelectedObject);
            }

            SelectedObject = newSelection;

            if (SelectedObject != null)
            {
                OnSelectionStart(SelectedObject);
            }
        }
    }
Example #18
0
    public override void Execute(Unit unit)
    {
        switch (unit.stance)
        {
        case Stance.Aggressive:
        case Stance.Defensive:
            Collider[] colliders = Physics.OverlapSphere(unit.transform.position, unit.viewRange - unit.navMeshAgent.radius, unit.attackableLayer);

            foreach (Collider collider in colliders)
            {
                IDamageable iDamageable = collider.GetComponent <IDamageable>();
                RTSObject   rtsObject   = iDamageable.GetOwner();

                if (rtsObject.team != unit.team)
                {
                    unit.SetTarget(iDamageable);
                    unit.startPosition = unit.transform.position;
                }
            }
            break;

        case Stance.Guard:
            colliders = Physics.OverlapSphere(unit.transform.position, unit.attackRange - unit.navMeshAgent.radius, unit.attackableLayer);

            foreach (Collider collider in colliders)
            {
                IDamageable iDamageable = collider.GetComponent <IDamageable>();
                RTSObject   rtsObject   = iDamageable.GetOwner();

                if (rtsObject.team != unit.team)
                {
                    unit.SetTarget(iDamageable);
                    unit.startPosition = unit.transform.position;
                }
            }
            break;

        case Stance.Hold:
        default:

            break;
        }
    }
    public override void Attack(RTSObject obj)
    {
        m_Target = obj;
        TargetSet = true;
        if (m_Target)
        {
            if (TargetInLine())
            {
                RotateTowards(TargetPos);
                if (canFire)
                {
                    // Is the target within maximum range?
                    if (TargetInRange())
                    {
                        Fire();

                        if (m_Target == null)
                        {
                            Stop();
                        }
                    }
                    else
                    {
                        Follow();
                    }
                }
                else
                {
                    WaitAndFire();
                }
            }
            else
            {
                RotateTowards(TargetPos);
            }
        }
        else
        {
            Stop();
        }
    }
Example #20
0
    public override void Execute(Unit unit)
    {
        if (!unit.navMeshAgent.pathPending)
        {
            if (unit.navMeshAgent.remainingDistance <= unit.navMeshAgent.stoppingDistance)
            {
                if (!unit.navMeshAgent.hasPath || unit.navMeshAgent.velocity.sqrMagnitude == 0f)
                {
                    unit.SwitchToState(StateType.Idle);
                    return;
                }
            }
        }

        switch (unit.stance)
        {
        case Stance.Aggressive:
            Collider[] colliders = Physics.OverlapSphere(unit.transform.position, unit.viewRange - unit.navMeshAgent.radius, unit.attackableLayer);

            foreach (Collider collider in colliders)
            {
                IDamageable iDamageable = collider.GetComponent <IDamageable>();
                RTSObject   rtsObject   = iDamageable.GetOwner();

                if (rtsObject.team != unit.team)
                {
                    unit.SetTarget(iDamageable);
                    break;
                }
            }
            break;

        default:
            break;
        }
    }
Example #21
0
    void Start()
    {
        //Инициализация
        anim = GetComponent <Animation>();
        rig  = GetComponent <Rigidbody>();
        Part = GetComponentInChildren <ParticleSystem>();
        Part.Stop();
        foreach (AnimationState clip in anim)
        {
            CHAR.Add(clip.name);
        }

        damage_timer = Time.time;



        target = transform;

        //PATHFINDING
        self = GetComponent <RTSObject>();
        UpdateCurrentTile();

        charS = CharS.Idle;
    }
 //-------------------------------------------------------------------------------------
 public bool IsCurrentUnit(RTSObject obj)
 {
     return currentObject == obj.gameObject;
 }
Example #23
0
    /// <summary>
    /// Cancels an attack sequence on the given target.
    /// </summary>
    private void EndAttack()
    {
        // If we were moving to the target to attack it, cancel this move
        if (CanMove () && HasPath ()) {
            CancelPath ();
        }

        // Disable the attack status
        target = null;
        attacking = false;
        remainingTimeToAttack = 0;
    }
Example #24
0
 public RightButton_Handler(int x, int y, int button, RTSObject target) : base(x, y, button, target)
 {
 }
 public abstract void Attack(RTSObject obj);
 public static Order CreateAttackOrder(RTSObject obj)
 {
     return new Order("Attack", 2, obj);
 }
Example #27
0
 public void onAttackOrder(OrderAction action, RTSObject obj)
 {
     selectedObjects.AssignTask(action, new AttackTask(obj));
 }
 public void NoLongerOccupied(RTSObject occupiedBy)
 {
     OccupiedBy = null;
     m_OccupiedStatic = false;
 }
Example #29
0
 public void NoLongerOccupied(RTSObject occupiedBy)
 {
     OccupiedBy     = null;
     Occupied       = false;
     OccupiedStatic = false;
 }
Example #30
0
    /// <summary>
    /// Begins an attack on the given target object.
    /// To stop the current attack sequence, pass null to this method.
    /// </summary>
    /// <param name="target">The target of the attack. If null is given, the attack will stop.</param>
    public void AttackObject(RTSObject target)
    {
        if (!CanAttack ())
            throw new InvalidOperationException ("Called AttackObject over an object that can't attack.");

        if (target != null) {
            if (!target.CanBeAttacked ())
                throw new InvalidOperationException ("Called AttackObject over a target object that can't defend.");

            BeginAttack (target);
        } else {
            EndAttack ();
        }
    }
 public void DeselectObject(RTSObject obj)
 {
     if (obj is IOrderable)
     {
         SelectedActiveObjects.Remove ((IOrderable)obj);
     }
     obj.SetDeselected ();
     SelectedObjects.Remove (obj);
 }
 public void SetOccupied(RTSObject occupiedBy, bool occupiedStatic)
 {
     OccupiedBy = occupiedBy;
     m_OccupiedStatic = occupiedStatic;
 }
Example #33
0
    /// <summary>
    /// Begins an attack sequence on the given target.
    /// </summary>
    /// <param name="newTarget">The target of the attack.</param>
    public void BeginAttack(RTSObject newTarget)
    {
        target = newTarget;
        attacking = true;
        remainingTimeToAttack = 0;

        PerformAttack ();
    }
Example #34
0
 public bool Contains(RTSObject obj)
 { // Checks whether or not the object is selected
     return(selectedObjs.Contains(obj));
 }
Example #35
0
 public List <RTSObject> RemoveObject(RTSObject obj)
 {
     _objects.Remove(obj);
     return(_objects);
 }
Example #36
0
 public static Order CreateAttackOrder(RTSObject obj)
 {
     return(new Order("Attack", 2, obj));
 }
Example #37
0
 public AttackTask(RTSObject obj)
 {
     _obj  = obj;
     _type = TaskType.Attack;
 }
Example #38
0
    void Update()
    {
        Vector3      pos;
        RaycastHit2D hit;

        RTSObject[] hits = null;

        if (Input.GetMouseButton(0) || Input.GetMouseButton(1))
        {
            pos = Input.mousePosition;
            pos = Camera.main.ScreenToWorldPoint(pos);

            hit = Physics2D.Raycast(pos, -Vector2.zero);
            RTSObject rtsHit = null;
            if (hit)
            {
                rtsHit = hit.transform.GetComponent <RTSObject>();
            }

            if (rtsHit)
            {
                hits = new RTSObject[1] {
                    rtsHit
                }
            }
            ;                                       // Objects that were clicked / were included in the selection box
        }

        // Select, Reselect, Deselect, and Unselect Orders
        if (hits != null && Input.GetMouseButtonDown(0))
        {
            if (Input.GetKey(KeyCode.LeftShift))
            {
                if (hits.Length == 1 && selectedObjects.Contains(hits[0]))
                {
                    onDeselectOrder(hits);
                }
                else
                {
                    onSelectOrder(hits);
                }
                return;
            }
            onReselectOrder(hits);
            return;
        }
        else if (hits == null && Input.GetMouseButtonDown(0))
        {
            onUnselectOrder();
            return;
        }

        // Move, Build, Gather, and Attack Orders
        if (hits != null && Input.GetMouseButtonDown(1))
        {
            if (Input.GetKey(KeyCode.LeftShift))
            {
                switch (hits[0].GetRTSObjectType())
                {
                case RTSObjectType.ResourceDeposit:
                    onGatherOrder(OrderAction.Additive, hits[0] as ResourceDeposit);
                    break;
                }
            }
            else
            {
                switch (hits[0].GetRTSObjectType())
                {
                case RTSObjectType.ResourceDeposit:
                    onGatherOrder(OrderAction.Singular, hits[0] as ResourceDeposit);
                    break;
                }
            }
            return;
        }
        else if (hits == null && Input.GetMouseButtonDown(1))
        {
            if (Input.GetKey(KeyCode.LeftShift))
            {
                onMoveOrder(OrderAction.Additive);
            }
            else
            {
                onMoveOrder(OrderAction.Singular);
            }
            return;
        }

        if (Input.GetKey(KeyCode.Delete))
        {
            onDeleteOrder();
        }
    }
Example #39
0
    //-------------------------------------------------------------------------------------

    public bool IsCurrentUnit(RTSObject obj)
    {
        return(currentObject == obj.gameObject);
    }
Example #40
0
 public List <RTSObject> AddObject(RTSObject obj)
 {
     _objects.Add(obj);
     return(_objects);
 }
Example #41
0
 /// <summary>
 /// Called when the RTS element selection ends.
 /// </summary>
 private void OnSelectionEnd(RTSObject obj)
 {
 }
Example #42
0
 /// <summary>
 /// Called when the RTS element selection begins.
 /// </summary>
 private void OnSelectionStart(RTSObject obj)
 {
 }
 public RightButton_Handler(int x, int y, int button, RTSObject target)
     : base(x, y, button, target)
 {
 }
Example #44
0
 public void SetOccupied(RTSObject occupiedBy, bool occupiedStatic)
 {
     OccupiedBy     = occupiedBy;
     Occupied       = true;
     OccupiedStatic = occupiedStatic;
 }
Example #45
0
 void Start()
 {
     rtsObject              = GetComponent <RTSObject>();
     rtsObject.enemyAttack += OnHPCahnged;
 }