Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using DG.Tweening;
- using UnityEngine;
- namespace Homebrew
- {
- public partial class ProcessingEnemy : ProcessingBase, ITick
- {
- [GroupExclude(Tag.StateOnGround)]
- public Group<ComponentEnemy, ComponentMotion, ComponentView, ComponentAnimation, ComponentObject> groupEnemies;
- public Group<ComponentPlayer> groupPlayers;
- public Dictionary<int, AIState> statesMap = new Dictionary<int, AIState>();
- public float delta;
- public float ticks;
- public ProcessingEnemy()
- {
- groupEnemies.Add += entity =>
- {
- var cDamageble = entity.ComponentDamageble();
- cDamageble.handle = HandleDamage;
- entity.ComponentView().parts[0].renderer.DOColor(new Color(1, 1, 1, 1), 0.3f).SetDelay(0.1f);
- };
- WanderSetup();
- AttackSetup();
- HitSetup();
- DeathSetup();
- }
- public void Tick()
- {
- delta = Time.delta;
- ticks = Time.frame;
- foreach (var entity in groupEnemies)
- {
- var cAI = entity.ComponentEnemy();
- cAI.GetPlayer(entity, groupPlayers);
- cAI.CheckState(entity, statesMap);
- statesMap[cAI.state].Handle(entity);
- statesMap[cAI.state].Condition(entity);
- }
- }
- void HandleDamage(int entity, ref SignalDamage arg)
- {
- var cAI = entity.ComponentEnemy();
- var cMotion = entity.ComponentMotion();
- var cHealth = entity.ComponentHealth();
- var template = entity.ComponentEnemy().template;
- ScriptChangeHealth.Handle(entity, arg.damage, template.invurableTime);
- if (cHealth.HP > 0)
- {
- if (!ScriptKnockback.Handle(entity, ref arg))
- {
- if (arg.conditionMelee)
- {
- ScriptHurt.Handle(entity, 1);
- ScriptShake.Handle(entity, ref arg);
- }
- cMotion.velocity.x += arg.forcePush * arg.direction;
- }
- }
- ScriptSplash.Handle(entity);
- ScriptHurtEffect.Handle(entity, arg.direction, template.prefabFxBlood, arg.positionHit);
- if (cHealth.HP == 0)
- {
- cAI.state = Tag.AIStateDeath;
- var pos = entity.ComponentObject().transform.position;
- if (entity.Has(Tag.StateBloodyDeath))
- {
- FactoryMisc.SpawnFlesh(pos, 3);
- if (Random.value >= 0.5f)
- {
- FactoryMisc.SpawnBloodWalls(pos.x);
- Game.evBloodyKill(entity);
- }
- FactoryMisc.SpawnBloodFloor(pos + new Vector3(0, -0.1f, 0));
- entity.Release(true);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement