示例#1
0
    /// <summary>
    /// Called when a unit is to enter/attack this tower.
    /// See documenation for full explaination and metrics.
    /// If unit is friendly, stationed units is increased.
    /// Raises ChangedFaction and AttackedByUnit events.
    /// </summary>
    /// <param name="unit">Unit.</param>
    public void UnitEntered(UnitBehavior unit)
    {
        if (unit.Faction == Faction)
        {
            // Friendly units are transfered to this towers group
            unit.TransferGroup(stationedGroup);
            unit.gameObject.SetActive(false);
        }
        else
        {
            // Hostile units damage this towers stationed unit group
            int strength = FactionController.GetAttackStrengthForFaction(unit.Faction);
            stationedGroup.Damage(strength);

            // Change tower's faction if last unit was killed
            if (stationedGroup.Empty)
            {
                TowerController.ConvertTowerToFaction(this, unit.Faction);
                if (ChangedFaction != null)
                {
                    ChangedFaction(Faction);
                    SetGraphic();
                }
            }

            unit.ImpactKill();

            if (AttackedByUnit != null)
            {
                AttackedByUnit(unit);
            }
        }
    }
示例#2
0
    /**
     * @brief Updates ball's movements and instantiates new ball objects when player press space.
     **/
    public override void OnSyncedUpdate()
    {
        FP   hor = (FP)TrueSyncInput.GetInt(INPUT_KEY_HORIZONTAL) / 100;
        FP   ver = (FP)TrueSyncInput.GetInt(INPUT_KEY_VERTICAL) / 100;
        bool currentCreateState = TrueSyncInput.GetInt(INPUT_KEY_CREATE) == 1;

        // Instantiates a new ball belonging to current player if the following criteria is true
        if (!lastCreateState && currentCreateState && !createdRuntime)
        {
            UnitBehavior otherSP = TrueSyncManager.SyncedInstantiate(prefab, tsTransform.position, tsTransform.rotation).GetComponent <UnitBehavior>();
            //otherSP.createdRuntime = true;
            //otherSP.owner = owner;

            lastCreateState = currentCreateState;

            return;
        }

        TSVector forceToApply = TSVector.zero;

        if (FP.Abs(hor) > FP.Zero)
        {
            forceToApply.x = hor / 3;
        }

        if (FP.Abs(ver) > FP.Zero)
        {
            forceToApply.z = ver / 3;
        }

        //controlledBody.AddForce(forceToApply, ForceMode.Impulse);

        lastCreateState = currentCreateState;
    }
示例#3
0
    private void ChooseAttackTarget()
    {
        float        minDistance  = float.MaxValue;
        UnitBehavior closestEnemy = null;

        foreach (UnitBehavior enemy in this.enemiesSpotted)
        {
            if (enemy.isDead)
            {
                continue;
            }

            float distance = Vector3.Distance(enemy.transform.position, this.transform.position);

            if (distance < minDistance)
            {
                minDistance  = distance;
                closestEnemy = enemy;
            }
        }

        if (closestEnemy)
        {
            this.SetAttackTarget(closestEnemy.gameObject);
        }
    }
示例#4
0
 void Awake()
 {
     CM = new ContextManager(this);
     stateTransitioner = new StateTransitioner(CM);
     unitBehavior      = new UnitBehavior(CM);
     TARGET_ENEMY      = CM.GetTargetEnemy();
 }
示例#5
0
    // Update is called once per frame
    void Update()
    {
        if (myUnit == null)
        {
            myUnit = gameObject.GetComponent <UnitBehavior>();
            return;
        }

        if (Target != null)
        {
            //move towards target during battle. eventually replace this entirely.
            //when in battle we shouldn't setoverworlddestination to anything because our turn queue will.
            if (myUnit.inBattle && !myUnit.isDead && isAlive)
            {
                //myUnit.SetOverworldDestination(Target.transform.position);
            }
            else
            {
                myUnit.SetOverworldDestination(Vector3.zero);
            }
        }



        //handle for the frame where we die via unitbehavior and need to trigger death animation.
        if (myUnit.isDead && isAlive)
        {
            isAlive = false;
            gameObject.transform.localScale *= 0.5f;
        }
    }
示例#6
0
 // Remove unit to list for attacking if unit isn't apart of tower's faction
 void OnUnitAttackTower(UnitBehavior unit)
 {
     if (unit.Faction != tower.Faction)
     {
         visibleUnits.Remove(unit);
     }
 }
示例#7
0
    //private Renderer rend;
    // Use this for initialization
    void Start()
    {
        target = gameObject.transform;

        uican = GameObject.Find("UICanvas").GetComponent <Canvas>();
        GameObject prefab = Resources.Load <GameObject>("CanvasTextObject");
        //(GameObject)UnityEditor.AssetDatabase.LoadAssetAtPath("Assets/Resources/CanvasTextObject.prefab", typeof(GameObject));
        Vector3 pos = Camera.main.ScreenToViewportPoint(target.transform.position);

        nametag   = Instantiate(prefab, pos, uican.transform.rotation).GetComponent <Text>();
        healthtag = Instantiate(prefab, pos, uican.transform.rotation).GetComponent <Text>();
        //Parent to the panel
        nametag.transform.SetParent(uican.transform, false);
        healthtag.transform.SetParent(uican.transform, false);
        nametag.transform.SetAsFirstSibling();
        healthtag.transform.SetAsFirstSibling();
        //Set the text box's text element font size and style:
        nametag.fontSize   = 20;
        healthtag.fontSize = 14;



        nametag.text             = target.name;
        nametag.transform.parent = uican.transform;
        uni            = target.GetComponent <UnitBehavior>();
        healthtag.text = uni.GetHealth().x.ToString();
        //TextMesh tm = GetComponent<TextMesh>();
    }
示例#8
0
 /// <summary>
 /// Creates UnitPrepMotor with given UnitBehavior.
 /// </summary>
 /// <param name="unit"></param>
 public UnitPrepMotor(UnitBehavior unit)
 {
     this.unit   = unit;
     originTower = null;
     animTime    = Random.Range(.5f, 1.0f);
     deactivate  = false;
 }
示例#9
0
 /// <summary>
 /// Creates a UnitMovementMotor with given UnitBehavior.
 /// </summary>
 /// <param name="unit">Unit to be driven by this motor.</param>
 public UnitMovementMotor(UnitBehavior unit)
 {
     this.unit    = unit;
     currentSpeed = 3.0f;
     maxSpeed     = 5.0f;
     acceleration = 5f;
 }
示例#10
0
    // Update is called once per frame
    void Update()
    {
        if (player == null)
        {
            player = GameObject.Find("OverWorldController").GetComponent <OverWorldControllerScript>().player;
            return;
        }

        //heal the player as long as they're here.
        if ((gameObject.transform.position - player.transform.position).magnitude < radius)
        {
            if (player.damage > incAmount)
            {
                player.damage -= incAmount;
            }
            else
            {
                player.damage = 0;
            }
            if (player.wounds > incAmount)
            {
                player.wounds -= incAmount;
            }
            else
            {
                player.wounds = 0;
            }
        }
    }
示例#11
0
    public void SpawnUnit()
    {
        GameObject   spawnedUnit         = Instantiate(catPrefab, this.transform.position, Quaternion.identity);
        UnitBehavior spawnedUnitBehavior = spawnedUnit.GetComponent <UnitBehavior>();

        spawnedUnitBehavior.MoveTo(this.transform.position + new Vector3(2, 0, 2));
    }
示例#12
0
 public void RemoveOccupied(UnitBehavior o)
 {
     if (objects.Contains(o))
     {
         objects.Remove(o);
     }
 }
示例#13
0
 public void AddOccupied(UnitBehavior o)
 {
     if (!objects.Contains(o))
     {
         objects.Add(o);
     }
 }
示例#14
0
 void OnUnitDeath(UnitBehavior unit)
 {
     if (unit.Faction == FactionController.PlayerFaction)
     {
         //FMOD_StudioSystem.instance.PlayOneShot(UnitKilledEvent.path, Camera.main.transform.position, Preferences.SFXVolume);
         AudioManager.PlayRandomUnitDeathSound();
     }
 }
示例#15
0
    public void OnDetectionRangeTriggerExit(Collider other)
    {
        UnitBehavior otherUnitBehavior = other.gameObject.GetComponent <UnitBehavior>();

        if (this.enemiesSpotted.Contains(otherUnitBehavior))
        {
            this.enemiesSpotted.Remove(otherUnitBehavior);
        }
    }
示例#16
0
 // Use this for initialization
 void Start()
 {
     unit = GetComponent<UnitBehavior>();
     if (unit is King)
     {
         transform.name = "King" + unit.Ruler;
     }
     minDistanceToKing = Random.Range(2, 10);
 }
示例#17
0
 // Use this for initialization
 void Start()
 {
     unit = GetComponent <UnitBehavior>();
     if (unit is King)
     {
         transform.name = "King" + unit.Ruler;
     }
     minDistanceToKing = Random.Range(2, 10);
 }
示例#18
0
 // call this to create a turn.
 public void Start(UnitBehavior s)
 {
     TargetLocator = GameObject.Instantiate(Resources.Load <GameObject>("ActionLocator"));
     SetRangeColor(TargetLocator);
     self = s;
     //properly offset this turn's origin point based on previous turns.
     origin = GetOrigin();
     SetTarget(origin + self.transform.Find("Model").forward);
 }
示例#19
0
    public bool isEnemy(Collider other)
    {
        UnitBehavior ub = other.GetComponent <UnitBehavior>();

        if (ub != null)
        {
            return(ub.Ruler != 0 && ub.Ruler != Ruler);
        }
        return(false);
    }
示例#20
0
 // Use this for initialization
 void Start()
 {
     playerObject = transform.GetComponent <OverWorldControllerScript>().getPlayer();
     playerRange  = playerObject.transform.Find("RangeIndicator").gameObject;
     cancelbutton.onClick.AddListener(ClickCancel);
     basicattack.onClick.AddListener(ClickAttack);
     castfirebutton.onClick.AddListener(ClickCast);
     movetobutton.onClick.AddListener(ClickMove);
     blockbutton.onClick.AddListener(ClickBlock);
     playbutton.onClick.AddListener(ClickPlay);
 }
示例#21
0
    public void OnDetectionRangeTriggerEnter(Collider other)
    {
        UnitBehavior otherUnitBehavior = other.gameObject.GetComponentInParent <UnitBehavior>();

        if (otherUnitBehavior && otherUnitBehavior.isEnemyUnit != this.isEnemyUnit)
        {
            this.enemiesSpotted.Add(otherUnitBehavior);
        }

        this.ChooseAttackTarget();
    }
示例#22
0
    // Create a unit of a type at the left or right flank
    private void CreateUnit(int type, int positionCode)
    {
        TSVector   position;
        GameObject prefab;
        int        attack = 1, hp = 1;
        FP         range = 0f;


        switch (type)
        {
        case 1:         // Melee Unit
            prefab = this.unitPrefab;
            attack = 10;
            hp     = 30;
            range  = 0f;
            break;

        case 2:         // Ranged Unit
            prefab = this.unit2Prefab;
            attack = 5;
            hp     = 20;
            range  = 3f;
            break;

        default:
            Debug.Log("Incorrect type specified by CreateUnit");
            return;
        }
        UnitData stats = new UnitData(hp, attack, range);


        switch (positionCode)
        {
        case 1:         // Left flank
            position = leftSpawn;
            break;

        case 2:         // Right flank
            position = rightSpawn;
            break;

        default:
            Debug.Log("Incorrect positionCode specified by CreateUnit");
            return;
        }

        position.x *= positionFactor;
        position.z *= positionFactor;
        UnitBehavior unitBehavior = TrueSyncManager.SyncedInstantiate(prefab, position, TSQuaternion.identity).GetComponent <UnitBehavior>();

        unitBehavior.owner = owner;
        unitBehavior.SetData(stats);
    }
示例#23
0
 // Removes unit from dictionary
 void UnitExited(UnitBehavior unit)
 {
     if (unitInBelt.ContainsKey(unit))
     {
         unitInBelt[unit] = false;
     }
     else
     {
         unitInBelt.Add(unit, false);
     }
     //exitPoints.Add(unit.transform.position);
 }
示例#24
0
文件: Tower.cs 项目: henryvstone/TDO
 // Update is called once per frame
 void Update()
 {
     foreach (Transform child in units.transform)
     {
         float distance = (child.position - this.transform.position).magnitude;
         if (distance < this.range)
         {
             UnitBehavior unit = child.GetComponent <UnitBehavior>();
             unit.setHealth(unit.getHealth() - this.damage);
         }
     }
 }
示例#25
0
	public void SetUnit (GameObject u) {
		if (unit != null) {
			behavior.state.OnHealthChange -= OnHealth;
		}
		// ---
		unit = u;
		behavior = unit.GetComponent <UnitBehavior> ();
		// ---
		behavior.state.OnHealthChange += OnHealth;
		// ---
		Redraw ();
	}
示例#26
0
 // Use this for initialization
 void Start()
 {
     //obtain unitbehavior from parent object if it is not already set.
     if (myunit == null)
     {
         myunit = gameObject.transform.parent.GetComponent <UnitBehavior>();
     }
     //obtain the model's animator if not already set.
     if (myanim == null)
     {
         myanim = gameObject.GetComponent <Animator>();
     }
 }
示例#27
0
    public void HandleAttackHitAnimationEvent()
    {
        if (!this.attackTargetGameObject)
        {
            this.ChooseAttackTarget();
            return;
        }

        UnitBehavior targetBehavior = this.attackTargetGameObject.GetComponent <UnitBehavior>();

        if (targetBehavior)
        {
            targetBehavior.TakeHit(30);
        }
    }
示例#28
0
    // Update is called once per frame
    public override void Update(float deltaTime)
    {
        // Orbit if at a location
        if (CurrentLocation != null)
        {
            // If too close, push out a bit
            Vector2 outVector = GetPosition() - CurrentLocation.GetPosition();
            if (Vector2.SqrMagnitude(outVector) < CurrentLocation.OrbitDistance * CurrentLocation.OrbitDistance)
            {
                representation.transform.position += new Vector3(outVector.x, outVector.y, 0) / 15;
            }
            // Orbit
            representation.transform.position = RotatePoint(representation.transform.position, CurrentLocation.GetPosition(), deltaTime * Mathf.PI / 3);

            if (currentBehavior == UnitBehavior.Defending)
            {
                return;
            }
        }

        if (currentBehavior == UnitBehavior.Stopped)
        {
            return;
        }

        //destination = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        // Move toward the destination if we aren't already at it
        if (Vector3.Distance(representation.transform.position, this.destination) < MovementRate * deltaTime)
        {
            representation.transform.position = this.destination;
            currentBehavior = UnitBehavior.Stopped;
            // Find closest base
            foreach (var b in owner.ReadBases())
            {
                if (Vector2.Distance(GetPosition(), b.GetPosition()) < 2 * b.Size)
                {
                    CurrentLocation = b;
                    return;
                }
            }
        }
        else
        {
            Vector2 moveVector = (this.destination - (Vector2)representation.transform.position).normalized * MovementRate * deltaTime;
            representation.transform.position += (Vector3)(moveVector);
        }
    }
示例#29
0
    /// <summary>
    /// Removes unit's Combat-given UI tags.
    /// </summary>
    /// <param name="unit">the unit within Combatants which acts as an indexer.</param>
    private void Kill(UnitBehavior unit)
    {
        //remove from fighters list.
        //Debug.Log("Kill_ started");
        ActiveCombatants.Remove(unit);
        //clean up actions
        unit.ClearCombatActionQueue();

        /*
         * //remove it's health over target entity.
         * if (unit.gameObject.GetComponent<HealthOverTarget>())
         * {
         *  Destroy(unit.gameObject.GetComponent<HealthOverTarget>());
         * }
         */
        //Debug.Log("Kill_ Ended");
    }
示例#30
0
    void Start()
    {
        unitRigidbody = GetComponentInParent <Rigidbody2D>();
        unit          = GetComponentInParent <UnitBehavior>();
        animator      = GetComponent <Animator>();

        witchDistance = GetComponentInParent <UnitBehavior>().witchDistance;
        lastAim       = new Vector2(1, 0);

        if (gameObject.name.Equals("Witch"))
        {
            color = GameInformation.pink;
        }
        else
        {
            color = GameInformation.purple;
        }
    }
示例#31
0
    Vector3 GetClosestUnitPosition()
    {
        var          units       = GameObject.FindObjectsOfType <UnitBehavior>();
        var          distance    = 9000F;
        UnitBehavior closestUnit = null;

        foreach (var unit in units)
        {
            var currentDistance = Vector3.Distance(transform.position, unit.transform.position);
            if (currentDistance < distance)
            {
                closestUnit = unit;
                distance    = currentDistance;
            }
        }

        return(closestUnit.transform.position);
    }
示例#32
0
    /// <summary>
    /// changes color of the room's roof object based on relative position.
    /// also changes the floor flags for the minimap class to use
    /// </summary>
    void UpdateRoofing()
    {
        if (target == null || target.model == null)
        {
            //Debug.Log("target or target model is null, so no roof to update.");
            return;
        }
        foreach (WRoom o in myfloor.map)
        {
            o.SetVisionColor(UnvisibleColor);
            o.SetActive(false);
        }

        //now we have a target, make the target room's roof clear, and the connection rooms semi-clear
        target.SetActive(true);
        //target.model.transform.Find("Roof").GetComponent<Renderer>().material.SetColor("_MainColor", CurrentRoomColor);
        target.SetVisionColor(CurrentRoomColor);
        //set hasbeenrevealed for this object which the player is now in.
        target.hasBeenRevealed = true;
        //set hasbeenvisited for this object which the player is now in.
        target.hasBeenVisited = true;
        CameraControllerOfflineScript cam = GameObject.Find("Camera").GetComponent <CameraControllerOfflineScript>();

        cam.Target2 = target.model;
        UnitBehavior unit = playerObject.GetComponent <UnitBehavior>();

        if (unit != null)
        {
            cam.SetBattle(unit.inBattle); //lets the camera know whether to zoom out or not.
        }
        for (int i = 0; i < 4; i++)
        {
            if (target.connections[i] != null)
            {
                //target.connections[i].model.transform.Find("Roof").GetComponent<Renderer>().material.SetColor("_MainColor", ConnectedRoomColor);
                target.connections[i].SetActive(true);
                target.connections[i].SetVisionColor(ConnectedRoomColor);
                //since this connected room is partially revealed, reflect this in the map.
                target.connections[i].hasBeenRevealed = true;
            }
        }
    }
示例#33
0
 public void SetBehavior(UnitBehavior behave)
 {
     behavior = behave;
 }