Advertisement
dimmpixeye

Untitled

Jan 21st, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.35 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using DG.Tweening;
  3. using UnityEngine;
  4.  
  5. namespace Homebrew
  6. {
  7.     public partial class ProcessingEnemy : ProcessingBase, ITick
  8.     {
  9.         [GroupExclude(Tag.StateOnGround)]
  10.         public Group<ComponentEnemy, ComponentMotion, ComponentView, ComponentAnimation, ComponentObject> groupEnemies;
  11.         public Group<ComponentPlayer> groupPlayers;
  12.  
  13.         public Dictionary<int, AIState> statesMap = new Dictionary<int, AIState>();
  14.  
  15.  
  16.         public float delta;
  17.         public float ticks;
  18.  
  19.         public ProcessingEnemy()
  20.         {
  21.             groupEnemies.Add += entity =>
  22.             {
  23.                 var cDamageble = entity.ComponentDamageble();
  24.                 cDamageble.handle = HandleDamage;
  25.    
  26.                 entity.ComponentView().parts[0].renderer.DOColor(new Color(1, 1, 1, 1), 0.3f).SetDelay(0.1f);
  27.             };
  28.  
  29.  
  30.             WanderSetup();
  31.             AttackSetup();
  32.             HitSetup();
  33.             DeathSetup();
  34.         }
  35.  
  36.         public void Tick()
  37.         {
  38.             delta = Time.delta;
  39.             ticks = Time.frame;
  40.             foreach (var entity in groupEnemies)
  41.             {
  42.                 var cAI = entity.ComponentEnemy();
  43.  
  44.                 cAI.GetPlayer(entity, groupPlayers);
  45.                 cAI.CheckState(entity, statesMap);
  46.                 statesMap[cAI.state].Handle(entity);
  47.                 statesMap[cAI.state].Condition(entity);
  48.             }
  49.         }
  50.  
  51.         void HandleDamage(int entity, ref SignalDamage arg)
  52.         {
  53.             var cAI     = entity.ComponentEnemy();
  54.             var cMotion = entity.ComponentMotion();
  55.             var cHealth = entity.ComponentHealth();
  56.  
  57.             var template = entity.ComponentEnemy().template;
  58.             ScriptChangeHealth.Handle(entity, arg.damage, template.invurableTime);
  59.  
  60.             if (cHealth.HP > 0)
  61.             {
  62.                 if (!ScriptKnockback.Handle(entity, ref arg))
  63.                 {
  64.                     if (arg.conditionMelee)
  65.                     {
  66.                         ScriptHurt.Handle(entity, 1);
  67.                         ScriptShake.Handle(entity, ref arg);
  68.                     }
  69.  
  70.                     cMotion.velocity.x += arg.forcePush * arg.direction;
  71.                 }
  72.             }
  73.  
  74.  
  75.             ScriptSplash.Handle(entity);
  76.             ScriptHurtEffect.Handle(entity, arg.direction, template.prefabFxBlood, arg.positionHit);
  77.  
  78.  
  79.             if (cHealth.HP == 0)
  80.             {
  81.                 cAI.state = Tag.AIStateDeath;
  82.                 var pos = entity.ComponentObject().transform.position;
  83.                 if (entity.Has(Tag.StateBloodyDeath))
  84.                 {
  85.                     FactoryMisc.SpawnFlesh(pos, 3);
  86.  
  87.                     if (Random.value >= 0.5f)
  88.                     {
  89.                         FactoryMisc.SpawnBloodWalls(pos.x);
  90.                         Game.evBloodyKill(entity);
  91.                     }
  92.  
  93.                     FactoryMisc.SpawnBloodFloor(pos + new Vector3(0, -0.1f, 0));
  94.                     entity.Release(true);
  95.                 }
  96.             }
  97.         }
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement