Exemplo n.º 1
0
        // return true when duration has elapsed
        public bool Update(DateTime tick)
        {
            if (tickMs != 0 && (tick - lastTick).TotalMilliseconds >= tickMs)
            {
                lastTick = tick;
                if (LuaEngine.CallLuaStatusEffectFunction(this.owner, this, "onTick", this.owner, this) > 0)
                {
                    return(true);
                }
            }

            if (duration >= 0 && tick >= endTime)
            {
                return(true);
            }
            return(false);
        }
        public bool RemoveStatusEffect(StatusEffect effect, bool silent = false)
        {
            bool removedEffect = false;

            if (effect != null && effects.ContainsKey(effect.GetStatusEffectId()))
            {
                // send packet to client with effect remove message
                if (!silent && !effect.GetSilent() && (effect.GetFlags() & (uint)StatusEffectFlags.Silent) == 0)
                {
                    owner.DoBattleAction(0, 0, new CommandResult(owner.actorId, 30331, effect.GetStatusEffectId()));
                }

                //hidden effects not in charawork
                var index = Array.IndexOf(owner.charaWork.status, effect.GetStatusId());
                if (!effect.GetHidden() && index != -1)
                {
                    SetStatusAtIndex(index, 0);
                    SetTimeAtIndex(index, 0);
                }
                // function onLose(actor, effect)
                effects.Remove(effect.GetStatusEffectId());
                if (effect.script != null)
                {
                    effect.CallLuaFunction(owner, "onLose", owner, effect);
                }
                else
                {
                    LuaEngine.CallLuaStatusEffectFunction(this.owner, effect, "onLose", this.owner, effect);
                }
                owner.RecalculateStats();
                sendUpdate    = true;
                removedEffect = true;
            }

            return(removedEffect);
        }
        public bool AddStatusEffect(StatusEffect newEffect, Character source, bool silent = false, bool hidden = false)
        {
            /*
             *  worldMasterTextId
             *  32001 [@2B([@IF($E4($EB(1),$EB(2)),you,[@IF($E9(7),[@SHEETEN(xtx/displayName,2,$E9(7),1,1)],$EB(2))])])] [@IF($E4($EB(1),$EB(2)),resist,resists)] the effect of [@SHEET(xtx/status,$E8(11),3)].
             *  32002 [@SHEET(xtx/status,$E8(11),3)] fails to take effect.
             */

            var effect = GetStatusEffectById(newEffect.GetStatusEffectId());

            bool canOverwrite = false;

            if (effect != null)
            {
                var overwritable = effect.GetOverwritable();
                canOverwrite = (overwritable == (uint)StatusEffectOverwrite.Always) ||
                               (overwritable == (uint)StatusEffectOverwrite.GreaterOnly && (effect.GetDuration() < newEffect.GetDuration() || effect.GetMagnitude() < newEffect.GetMagnitude())) ||
                               (overwritable == (uint)StatusEffectOverwrite.GreaterOrEqualTo && (effect.GetDuration() <= newEffect.GetDuration() || effect.GetMagnitude() <= newEffect.GetMagnitude()));
            }

            if (canOverwrite || effect == null)
            {
                // send packet to client with effect added message
                if (effect != null && (!silent || !effect.GetSilent() || (effect.GetFlags() & (uint)StatusEffectFlags.Silent) == 0))
                {
                    // todo: send packet to client with effect added message
                }

                // wont send a message about losing effect here
                if (canOverwrite)
                {
                    effects.Remove(newEffect.GetStatusEffectId());
                }

                newEffect.SetStartTime(DateTime.Now);
                newEffect.SetEndTime(DateTime.Now.AddSeconds(newEffect.GetDuration()));
                newEffect.SetOwner(owner);

                if (effects.Count < MAX_EFFECTS)
                {
                    if (newEffect.script != null)
                    {
                        newEffect.CallLuaFunction(this.owner, "onGain", this.owner, newEffect);
                    }
                    else
                    {
                        LuaEngine.CallLuaStatusEffectFunction(this.owner, newEffect, "onGain", this.owner, newEffect);
                    }
                    effects.Add(newEffect.GetStatusEffectId(), newEffect);
                    //newEffect.SetSilent(silent);
                    newEffect.SetHidden(hidden);

                    if (!newEffect.GetHidden())
                    {
                        int index = 0;

                        //If effect is already in the list of statuses, get that index, otherwise find the first open index
                        if (owner.charaWork.status.Contains(newEffect.GetStatusId()))
                        {
                            index = Array.IndexOf(owner.charaWork.status, newEffect.GetStatusId());
                        }
                        else
                        {
                            index = Array.IndexOf(owner.charaWork.status, (ushort)0);
                        }

                        SetStatusAtIndex(index, newEffect.GetStatusId());
                        //Stance statuses need their time set to an extremely high number so their icon doesn't flash
                        //Adding getduration with them doesn't work because it overflows
                        uint time = (newEffect.GetFlags() & (uint)StatusEffectFlags.Stance) == 0 ? Utils.UnixTimeStampUTC(newEffect.GetEndTime()) : 0xFFFFFFFF;
                        SetTimeAtIndex(index, time);
                    }
                    owner.RecalculateStats();
                }
                return(true);
            }
            return(false);
        }