Beispiel #1
0
    public string takeDamage(Entity self, int damage)
    {
        if (damage > 0)
        {
            hp -= damage;
            self.GetComponentInChildren <Animator>().Play("takeDamage");
            self.gameObject.GetComponentInChildren <HealthBarScale>().setScalePercent(Mathf.Clamp((float)hp / (float)max_hp, 0f, 1f));
            //if (self.ai != null)
            self.gameObject.GetComponentInChildren <DamagePopupSpawner>().spawnDamagePopup(damage.ToString(), "red");
            if (hp <= 0)
            {
                self.GetComponentInChildren <Animator>().SetTrigger("die");
                self.blocks = false;
                string info = "";
                if (!(self is Hero))
                {
                    Hero h = (Hero)GameController.objects[0];
                    h.experience_points += self.ai.xp;
                    info += h.checkLevelUp();
                }

                self.GetComponentInChildren <SpriteRenderer>().sortingOrder -= 1;
                info   += self.name + " has been defeated. You gain " + self.ai.xp + " experience points.\n";
                self.ai = null;
                return(info);
            }
        }
        return("");
    }
Beispiel #2
0
 private void toggleObjectsInTile(int x, int y, bool isEnabled)
 {
     for (int i = 1; i < GameController.objects.Count; i++)
     {
         Entity e = GameController.objects[i];
         if (e.gridPosition.x == x && e.gridPosition.y == y)
         {
             try { e.GetComponentInChildren <Canvas>().enabled = isEnabled; }catch {}
             e.GetComponentInChildren <SpriteRenderer>().enabled = isEnabled;
         }
     }
 }
Beispiel #3
0
    private void Awake()
    {
        rigidbody_2d = GetComponent <Rigidbody2D>();

        // After a few seconds from spawning, the snowball will
        // be destroyed from the game to save performance
        Invoke("DestroySnowball", time_until_destroy);

        parent_entity = GetComponentInParent <Entity>();

        // Ignores the collision between itself and its parent
        var parent_collider = parent_entity.GetComponent <Collider2D>();

        if (parent_collider != null)
        {
            Physics2D.IgnoreCollision(
                GetComponent <Collider2D>(),
                parent_collider);
        }

        // Ignores the collision between itself and other snowballs
        Physics2D.IgnoreLayerCollision(9, 9);

        if (fire_automatically)
        {
            // Ignores the boss collider
            Physics2D.IgnoreCollision(
                GetComponent <Collider2D>(),
                parent_entity.GetComponentInChildren <BoxCollider2D>());

            rigidbody_2d.AddRelativeForce(Vector2.up * speed * Time.deltaTime * speed_multiplier);
        }
    }
	protected void Update()
	{
		if(player == null || weapon == null)
		{
			player = EntityUtils.GetEntityWithTag("Player");

			if(player == null)
			{
				return;
			}

			weapon = player.GetComponentInChildren<Weapon>().transform.parent;
			eyes = player.transform.Find("Eyes");

			delay = new Vector3(0f, 0f, 0f);
			previous = new Vector2(eyes.rotation.eulerAngles.x, player.transform.rotation.eulerAngles.y);
			target = previous;
			normalAnim.localPosition = baseNormal;
			adsAnim.localPosition = baseAds;
		}

		previous = target;
		target = new Vector2(eyes.rotation.eulerAngles.x, player.transform.rotation.eulerAngles.y);
		if(previous.x > 270f && target.x < 90f) { previous.x -= 360f; }
		else if(previous.x < 90f && target.x > 270f) { previous.x += 360f; }
		if(previous.y > 270f && target.y < 90f) { previous.y -= 360f; }
		else if(previous.y < 90f && target.y > 270f) { previous.y += 360f; }
		delay = Vector3.Slerp (delay, new Vector3 (previous.x - target.x, previous.y - target.y, 0f), 0.1f);

		walking = player.GetComponent<CharacterController> ().velocity != Vector3.zero;
	}
Beispiel #5
0
    void FixedUpdate()
    {
        // target and caster still around?
        // note: we keep flying towards it even if it died already, because
        //       it looks weird if fireballs would be canceled inbetween.
        if (target != null && caster != null)
        {
            // move closer and look at the target
            var goal = target.GetComponentInChildren <Collider>().bounds.center;
            transform.position = Vector3.MoveTowards(transform.position, goal, speed);
            transform.LookAt(goal);

            // reached it?
            if (transform.position == goal)
            {
                // still alive? deal damage
                if (target.hp > 0)
                {
                    caster.DealDamageAt(target, damage, aoeRadius);
                }
                // done, destroy self
                NetworkServer.Destroy(gameObject);
            }
        }
        else
        {
            // destroy self
            NetworkServer.Destroy(gameObject);
        }
    }
 void setHighlightColor(Entity entity)
 {
     if (currentCharacterSelected != null)
     {
         currentCharacterSelected.GetComponentInChildren<SpriteRenderer>().color = Color.white;
     }
     entity.GetComponentInChildren<SpriteRenderer>().color = highlightColor;
 }
    internal override void Init(Animator animator)
    {
        base.Init(animator);

        if (m_AimCtrl == null && Entity != null)
        {
            m_AimCtrl = Entity.GetComponentInChildren <IKAimCtrl>();
        }
    }
Beispiel #8
0
 public override void Do(Entity source, Entity Target)
 {
     base.Do(source, Target);
     if (source is Player)
     {
         source.GetComponentInChildren <Animator>().SetTrigger(animationName);
         (source as Player).BonusDef += Defense;
     }
 }
Beispiel #9
0
 private void OnEnable()
 {
     entity = (Entity)target;
     button = new TypeSelectorButton <Trait>(
         new GUIContent("Add Trait"),
         AddTrait,
         TraitExtensions.FindTraitLocation,
         type => entity.GetComponentInChildren(type) != null
         );
 }
Beispiel #10
0
    /*------------------------------------------------------------------*\
    |*							Constructor
    \*------------------------------------------------------------------*/

    public HealthComponent(Entity entity, float healt)
    {
        Entity  = entity;
        Health  = healt;
        Total   = healt;
        Percent = 100;

        healthBar = Entity.GetComponentInChildren <HealthBar>();
        healthBar.InitHealth(healt);
    }
Beispiel #11
0
    static int GetComponentInChildren(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        Entity    obj  = LuaScriptMgr.GetNetObject <Entity>(L, 1);
        Type      arg0 = LuaScriptMgr.GetTypeObject(L, 2);
        Component o    = obj.GetComponentInChildren(arg0);

        LuaScriptMgr.Push(L, o);
        return(1);
    }
Beispiel #12
0
 private void getEnemiesInSight()
 {
     targets.Clear();
     for (int i = 1; i < GameController.objects.Count; i++)
     {
         Entity e = GameController.objects[i];
         if (e.GetComponentInChildren <SpriteRenderer>().enabled&& e.ai != null)
         {
             targets.Add(e);
         }
     }
 }
Beispiel #13
0
    public virtual void DealDamageAt(Entity entity, int n)
    {
        // subtract defense (but leave at least 1 damage, otherwise it may be
        // frustrating for weaker players)
        // [dont deal any damage if invincible]
        var dmg = !entity.invincible ? Mathf.Max(n - entity.defense, 1) : 0;

        entity.hp -= dmg;

        // show damage popup in observers via ClientRpc
        entity.RpcShowDamagePopup(dmg, entity.GetComponentInChildren <Collider>().bounds.center);
    }
    private void SelectEntity(Entity entity)
    {
        SelectedEntities.Add(entity);

        SelectionMarker selectionMarker = entity.GetComponentInChildren <SelectionMarker>(true);

        if (selectionMarker != null)
        {
            selectionMarker.ToggleRendering(true);
        }

        entity.Select();
    }
Beispiel #15
0
    /// <summary>
    /// Calculating position offsets and assigning parameters
    /// </summary>
    /// <param name="building">Entity component of building</param>
    public void SelectedBuilding(Entity building)
    {
        buildingPreb = building.gameObject;

        offs = new Vector3(building.size.x / 2, building.size.y / 2, 0);

        // because of origin issue 2 and folds
        if ((int)building.size.x % 2 == 0)
        {
            offs.x -= 0.5f;
        }
        else
        {
            offs.x = Mathf.FloorToInt(offs.x);
        }
        if ((int)building.size.y % 2 == 0)
        {
            offs.y -= 0.5f;
        }
        else
        {
            offs.y = Mathf.FloorToInt(offs.y);
        }
        spriteRenderer.sprite = building.sprite;
        spriteRenderer.size   = building.size;


        building.GetComponentInChildren <BoxCollider2D>().size = building.size;

        TMPro.TextMeshPro text = draggingPreb.GetComponentInChildren <TMPro.TextMeshPro>();
        text.rectTransform.sizeDelta = building.size;
        text.text = building._name;

        storedColor      = building.GetComponentInChildren <SpriteRenderer>().color;
        isBuildingPicked = true;

        draggingPreb.SetActive(isBuildingPicked);
    }
Beispiel #16
0
 public override void Do(Entity Source, Entity Target)
 {
     base.Do(Source, Target);
     Source.GetComponentInChildren <Animator>().SetTrigger("Hook");
     Source.transform.DOPunchPosition((Target.transform.position - Source.transform.position) / 2, 0.7f, 0).OnComplete(() => Player.instance.CheckActions());
     if (Target is Enemy)
     {
         (Target as Enemy).TakeDamage(Damage);
     }
     if (Source is Player)
     {
         (Source as Player).currentPoints -= 1;
     }
 }
Beispiel #17
0
    public override void Do(Entity source)
    {
        source.GetComponentInChildren <Animator>().SetTrigger("Hook");
        (source as Enemy).ready = false;
        source.transform.DOPunchPosition((Player.instance.transform.position - source.transform.position) / 2, 0.7f, 0).OnComplete(() => (source as Enemy).ready = true);
        var dir = Player.instance.transform.position - source.transform.position;

        source.LookTo(dir.Unidirectional());
        Player.instance.TakeDamage(Damage);
        if (source is Enemy)
        {
            (source as Enemy).actionPoints -= actionCost;
        }
    }
Beispiel #18
0
        /*------------------------------------------------------------------*\
        |*							HOOKS
        \*------------------------------------------------------------------*/

        protected virtual void Start()
        {
            entity = GetComponent <Entity>();

            entity.extensions
            .Find("HealthBar").gameObject
            .SetActive(true);
            Bar = entity.GetComponentInChildren <HealthBar>();
            if (Bar)
            {
                Bar.InitHealth(Total);
            }

            Current = Total;
            Percent = 100;
        }
    private void DeselectEntity(Entity entity, bool removeFromSelection)
    {
        SelectionMarker selectionMarker = entity.GetComponentInChildren <SelectionMarker>();

        if (selectionMarker != null)
        {
            selectionMarker.ToggleRendering(false);
        }

        if (removeFromSelection)
        {
            SelectedEntities.Remove(entity);
        }

        entity.Deselect();
    }
Beispiel #20
0
    void UpdateInventory()
    {
        int count = 0;

        foreach (InventoryItem item in e.GetComponentInChildren <Container>().invs[0].items)
        {
            Transform current = invGrid.GetChild(count);

            current.GetComponent <InventoryCase>().item = item;


            count++;
        }

        // Update preview
    }
Beispiel #21
0
 private void MakeIttleStrong(Entity ent, bool isLikeABoss)
 {
     if (ent != null)
     {
         Killable killable = ent.GetComponentInChildren <Killable>();
         if (killable != null)
         {
             if (isLikeABoss)
             {
                 killable.CurrentHp = 0;
             }
             else
             {
                 killable.CurrentHp = killable.MaxHp;
             }
         }
     }
 }
        public MissingAnimatorParameter(
            Entity entity,
            string name,
            AnimatorControllerParameterType parameterType,
            Trait requisitor
            ) : base(requisitor, entity, $"Entity {entity.name}'s animator not have a parameter named {name} of type {parameterType} which is a dependency of {requisitor} ")
        {
            ParameterName = name;
            ParameterType = parameterType;
#if UNITY_EDITOR
            WithSolution($"Add {name} ({parameterType})",
                         () => {
                var animator = entity.GetComponentInChildren <Animator>();
                if (animator.runtimeAnimatorController is AnimatorController controller)
                {
                    controller.AddParameter(name, parameterType);
                }
            });
#endif
        }
Beispiel #23
0
    public override void Do(Entity source, Entity Target)
    {
        base.Do(source, Target);
        var dist = (source.transform.position - Target.transform.position).magnitude;

        if (dist >= Range + 1)
        {
            return;
        }
        source.GetComponentInChildren <Animator>().SetTrigger(animationName);
        if (source is Player)
        {
            (source as Player).currentPoints -= actionCost;
        }
        if (Target is Enemy)
        {
            (Target as Enemy).TakeDamage(Damage);
        }
        //Player.instance.CheckActions();
    }
Beispiel #24
0
    public Entity closestEntity()
    {
        Entity target      = null;
        float  closestDist = 1000;

        for (int i = 1; i < GameController.objects.Count; i++)
        {
            Entity e = GameController.objects[i];
            if (e.GetComponentInChildren <SpriteRenderer>().enabled&& e.ai != null)
            {
                float dist = distanceTo(e);
                if (dist < closestDist)
                {
                    target      = e;
                    closestDist = dist;
                }
            }
        }
        return(target);
    }
Beispiel #25
0
    public string attack(Entity self, Entity target)
    {
        // Hit if rnd()*ATK > rnd()*DEF
        float isHit =
            self.fighterComponent.power * UnityEngine.Random.Range(0f, 1f)
            -
            target.fighterComponent.defense * UnityEngine.Random.Range(0f, 1f);

        //Debug.Log(self.name+"->"+target.name+" = "+isHit);

        self.GetComponentInChildren <Animator>().Play("attackSide");
        if (isHit < 0.0f)
        {
            AudioSource.PlayClipAtPoint(parrySound, target.transform.position);
            target.gameObject.GetComponentInChildren <DamagePopupSpawner>().spawnDamagePopup("miss", "red");
            return(self.name + " attacks " + target.name + " but it misses.\n");
        }

        //a simple formula for attack damage
        int damage = UnityEngine.Random.Range(self.fighterComponent.power - target.fighterComponent.defense,
                                              self.fighterComponent.power - target.fighterComponent.defense + Mathf.RoundToInt(isHit));

        //int damage = self.fighterComponent.power - target.fighterComponent.defense + Mathf.RoundToInt(isHit);

        string info = "";

        if (damage > 0)
        {
            Instantiate(slashEffect, target.transform.position, Quaternion.identity);
            AudioSource.PlayClipAtPoint(slashSound, target.transform.position);
            info  = target.fighterComponent.takeDamage(target, damage) + info;
            info += self.name + " attacks " + target.name + " for " + damage + " hit points.\n";
        }
        else
        {
            info = self.name + " attacks " + target.name + " but it has no effect.\n";
        }
        return(info);
    }
Beispiel #26
0
        // Setup the template skill for us to use
        private static void SetupTempalteSkill()
        {
            // Grab an existing skill to use as reference for weapon stats
            Entity existingSkill = GameManager.instance.allSkills[0];

            templateMaterial = existingSkill.GetComponentInChildren <MeshRenderer>().material;

            // Create the skill entity
            templateSkill       = GameObject.Instantiate(new GameObject("TemplateSkill", typeof(ItemView)), GrowthHackerAPI.prefabHelper.transform);
            templateSkill.layer = 15;
            // Attach collider
            CapsuleCollider collider = templateSkill.AddComponent <CapsuleCollider>();

            collider.radius    = 0.4f;
            collider.height    = 1.25f;
            collider.center    = Vector3.up * 0.626f;
            collider.direction = 1;
            // Attach ModPickup Entity
            ModPickup modPickup = templateSkill.AddComponent <ModPickup>();

            modPickup.isGrabbable = true;
            modPickup.weaponStats = existingSkill.weaponStats; // Just steal it from another skill

            // Create model wrapper
            GameObject modelParent = new GameObject("Visuals");
            Rotate     rotate      = modelParent.AddComponent <Rotate>();

            rotate.rotation   = Vector3.up;
            rotate.speed      = 50;
            modelParent.layer = 15;
            modelParent.transform.SetParent(templateSkill.transform);

            // Create skill holder
            GameObject entityMod = new GameObject("Mod");

            entityMod.layer = 15;
            entityMod.transform.SetParent(templateSkill.transform);
        }
Beispiel #27
0
    void FixedUpdate()
    {
        if (target != null && caster != null)
        {
            var goal = target.GetComponentInChildren <Collider>().bounds.center;
            transform.position = Vector3.MoveTowards(transform.position, goal, speed);
            transform.LookAt(goal);

            if (transform.position == goal)
            {
                if (target.hp > 0)
                {
                    caster.DealDamageAt(target, damage, aoeRadius);
                }

                NetworkServer.Destroy(gameObject);
            }
            else
            {
                NetworkServer.Destroy(gameObject);
            }
        }
    }
        public override void Start()
        {
            if (this.Initialized)
            {
                return;
            }
            base.Start();
            this.XGCharacter = Core.Instance.XGCharacters[this.XGCharacterName];
            this.Direction   = ECameraDirection.North;

            _spriteComponent    = Entity.GetComponentInChildren <SpriteComponent>();
            _characterComponent = Entity.Get <CharacterComponent>();
            _animations         = new Dictionary <(EActionTypes, ECameraDirection), List <IndividualAnimation> >();

            _spriteComponent.SpriteProvider           = BuildSpriteSheet();
            _spriteComponent.SpriteType               = SpriteType.Sprite;
            _spriteComponent.IgnoreDepth              = false;
            _spriteComponent.Entity.Transform.Scale.Y = 2.5f;
            _characterComponent.FallSpeed             = 50f;
            _characterComponent.JumpSpeed             = 5f;
            _characterComponent.Gravity               = new Vector3(0, -12f, 0);
            _unmodifiedPosition = _spriteComponent.Entity.Transform.Position;
            _characterComponent.UpdatePhysicsTransformation();
        }
Beispiel #29
0
 public override void Init(Blackboard blackboard)
 {
     this.blackboard = blackboard;
     entity          = blackboard.GetValueFromKey <Entity>("entity");
     eyes            = entity.GetComponentInChildren <AISight>();
 }
Beispiel #30
0
    void DoSpawn(Vector3 P, Vector3 dir)
    {
        Vector3 vector;

        if (this._spawnOnFloor && PhysicsUtility.GetFloorPoint(P, 20f, 50f, this._floorLayer, out vector))
        {
            P.y = vector.y;
        }
        Vector3    vector2    = P + this._playerEnt.transform.localPosition;
        GameObject gameObject = Object.Instantiate <GameObject>(this._playerCamera, vector2 + this._playerCamera.transform.localPosition, this._playerCamera.transform.localRotation);

        gameObject.transform.localScale = this._playerCamera.transform.localScale;
        gameObject.name = this._playerCamera.name;
        CameraContainer component = gameObject.GetComponent <CameraContainer>();

        component.Init(this._playerCamera);
        Entity entity = Object.Instantiate <Entity>(this._playerEnt, vector2, base.transform.rotation);

        entity.name = this._playerEnt.name;
        if (component != null)
        {
            RoomSwitchable componentInChildren = entity.GetComponentInChildren <RoomSwitchable>();
            if (componentInChildren != null)
            {
                componentInChildren.SetLevelCamera(component);
            }
        }
        if (this._playerGraphics != null)
        {
            GameObject gameObject2 = Object.Instantiate <GameObject>(this._playerGraphics, entity.transform.position + this._playerGraphics.transform.localPosition, this._playerGraphics.transform.localRotation);
            gameObject2.transform.parent     = entity.transform;
            gameObject2.transform.localScale = this._playerGraphics.transform.localScale;
            gameObject2.name = this._playerGraphics.name;
        }
        entity.Init();
        entity.TurnTo(dir, 0f);
        FollowTransform componentInChildren2 = gameObject.GetComponentInChildren <FollowTransform>();

        if (componentInChildren2 != null)
        {
            componentInChildren2.SetTarget(entity.transform);
        }
        LevelCamera componentInChildren3 = gameObject.GetComponentInChildren <LevelCamera>();

        if (componentInChildren3 != null)
        {
            LevelRoom roomForPosition = LevelRoom.GetRoomForPosition(entity.WorldTracePosition, null);
            if (roomForPosition != null)
            {
                componentInChildren3.SetRoom(roomForPosition);
                roomForPosition.SetImportantPoint(vector2);
                LevelRoom.SetCurrentActiveRoom(roomForPosition, false);
            }
        }
        PlayerController controller = ControllerFactory.Instance.GetController <PlayerController>(this._controller);

        controller.ControlEntity(entity);
        controller.name = this._controller.name;
        entity.Activate();
        if (this._varOverrider != null)
        {
            this._varOverrider.Apply(entity);
        }
        EntityHUD componentInChildren4 = gameObject.GetComponentInChildren <EntityHUD>();

        if (componentInChildren4 != null)
        {
            componentInChildren4.Observe(entity, controller);
        }
        EntityObjectAttacher.Attacher attacher   = null;
        EntityObjectAttacher          component2 = base.GetComponent <EntityObjectAttacher>();

        if (component2 != null)
        {
            attacher = component2.GetAttacher();
        }
        EntityObjectAttacher.AttachTag attachTag = null;
        if (attacher != null)
        {
            attachTag = attacher.Attach(entity);
        }
        PlayerRespawner playerRespawner;

        if (this._respawner != null)
        {
            playerRespawner      = Object.Instantiate <PlayerRespawner>(this._respawner);
            playerRespawner.name = this._respawner.name;
        }
        else
        {
            GameObject gameObject3 = new GameObject("PlayerRespawer");
            playerRespawner = gameObject3.AddComponent <PlayerRespawner>();
        }
        playerRespawner.Init(entity, controller, componentInChildren3, componentInChildren2, componentInChildren4, this._gameSaver, attacher, attachTag, this._varOverrider, P, dir);
        VarHelper.PlayerObj = entity.gameObject;         // Store reference to player obj
        PlayerSpawner.OnSpawnedFunc onSpawnedFunc = PlayerSpawner.onSpawned;
        PlayerSpawner.onSpawned = null;
        if (onSpawnedFunc != null)
        {
            onSpawnedFunc(entity, gameObject, controller);
        }
        EventListener.PlayerSpawn(false);         // Invoke custom event
        Object.Destroy(base.gameObject);
    }
Beispiel #31
0
    public void StartBurningEffect(Entity entityWithEffect, float timeToDestroy)
    {
        GameObject burningEffect = Instantiate(burningParticleSystemGO, entityWithEffect.transform.position, Quaternion.identity);

        burningEffect.GetComponent <BurningParticles>().Init(entityWithEffect.GetComponentInChildren <SpriteRenderer>(), timeToDestroy);
    }
Beispiel #32
0
 public void OnUnitSelected(CustomizableUnit customizableUnit)
 {
     previewEntity = entityDatabase.GetEntityInstance(customizableUnit.SelectedPlayerUnit.unitType, Vector3.zero, Quaternion.identity, previewContainer);
     previewEntity.GetComponentInChildren <Vision>().enabled = false;
 }