public void CheckAttrib(PESkEntity entity, AttribType type, float value) { if (type == m_Current) { if (value < 0 || value > entity.GetAttribute(m_Max)) { entity.SetAttribute(m_Current, Mathf.Clamp(value, 0, entity.GetAttribute(m_Max))); } } else if (type == m_Max) { float currentValue = entity.GetAttribute(m_Current); if (currentValue > value) { entity.SetAttribute(m_Current, value); } } }
private static AttribType GetRandMaxAttr(int npcId, PESkEntity entity, AttribType[] ChangeAbleAttr) { float maxP = 0; AttribType FindAttr = ChangeAbleAttr[0]; RandomNpcDb.Item rand = RandomNpcDb.Get(npcId); RandomNpcDb.RandomInt randomint = new RandomNpcDb.RandomInt(); for (int i = 0; i < ChangeAbleAttr.Length; i++) { if (!rand.TryGetAttrRandom(ChangeAbleAttr[i], out randomint) || randomint.m_Max == 0) { continue; } float currentAttrP = (entity.GetAttribute(ChangeAbleAttr[i], false) - randomint.m_Min) / (randomint.m_Max - randomint.m_Min); if (currentAttrP > maxP) { FindAttr = ChangeAbleAttr[i]; maxP = currentAttrP; } } return(FindAttr); }
public static int CheckAttrbCase(PESkEntity peskentity) { RandomAttrChoce attr = new RandomAttrChoce(); AttribType type = attr.RandType(); float curvalue = peskentity.GetAttribute(type); switch (type) { case AttribType.Hunger: { float maxHunger = peskentity.GetAttribute(AttribType.HungerMax); if (curvalue <= maxHunger * NpcRandomTalkDb.Get((int)ENpcTalkType.Follower_hunger_medium)._value && curvalue > maxHunger * NpcRandomTalkDb.Get((int)ENpcTalkType.Follower_hunger_low)._value) { return(NpcRandomTalkDb.Get((int)ENpcTalkType.Follower_hunger_medium).Scenario.RandCase()); } else if (curvalue <= maxHunger * NpcRandomTalkDb.Get((int)ENpcTalkType.Follower_health_low)._value) { return(NpcRandomTalkDb.Get((int)ENpcTalkType.Follower_hunger_low).Scenario.RandCase()); } else { return(-1); } } // break; case AttribType.Hp: { float maxHp = peskentity.GetAttribute(AttribType.HpMax); if (curvalue <= maxHp * NpcRandomTalkDb.Get((int)ENpcTalkType.Follower_health_medium)._value && curvalue > maxHp * NpcRandomTalkDb.Get((int)ENpcTalkType.Follower_health_low)._value) { return(NpcRandomTalkDb.Get((int)ENpcTalkType.Follower_health_medium).Scenario.RandCase()); } else if (curvalue <= maxHp * NpcRandomTalkDb.Get((int)ENpcTalkType.Follower_health_low)._value) { return(NpcRandomTalkDb.Get((int)ENpcTalkType.Follower_health_low).Scenario.RandCase()); } else { return(-1); } } // break; case AttribType.Comfort: { float maxcomfort = peskentity.GetAttribute(AttribType.ComfortMax); if (curvalue <= maxcomfort * NpcRandomTalkDb.Get((int)ENpcTalkType.Follower_comfort_common)._value && curvalue > maxcomfort * NpcRandomTalkDb.Get((int)ENpcTalkType.Follower_comfort_medium)._value) { return(NpcRandomTalkDb.Get((int)ENpcTalkType.Follower_comfort_common).Scenario.RandCase()); } else if (curvalue <= maxcomfort * NpcRandomTalkDb.Get((int)ENpcTalkType.Follower_comfort_medium)._value && curvalue > maxcomfort * NpcRandomTalkDb.Get((int)ENpcTalkType.Follower_comfort_low)._value ) { return(NpcRandomTalkDb.Get((int)ENpcTalkType.Follower_comfort_medium).Scenario.RandCase()); } else if (curvalue <= maxcomfort * NpcRandomTalkDb.Get((int)ENpcTalkType.Follower_comfort_low)._value) { return(NpcRandomTalkDb.Get((int)ENpcTalkType.Follower_comfort_low).Scenario.RandCase()); } else { return(-1); } } // break; default: break; } return(-1); }