Exemple #1
0
 public override void Process()
 {
     Indicator.Alpha = (Unit.GetVisibility() == 2) ? 0.5f : 0;
     Indicator.SetPosition(Unit.X + Unit.FracX + Unit.Width / 2f, Unit.Y + Unit.FracY + Unit.Height / 2f, 1f + (((Unit.Width + Unit.Height) / 2f) - 1f) / 2f);
     Indicator.CurrentFrame = (Indicator.CurrentFrame + 1) % Indicator.Class.Phases;
     Indicator.DoUpdateView = true;
 }
Exemple #2
0
        public override void Process()
        {
            int meanWh = (Unit.Width + Unit.Height) / 2;

            for (int i = 0; i < meanWh * 2; i++)
            {
                float rX = Unit.Width / 2f;
                float rY = Unit.Height / 4f;

                float randRad = UnityEngine.Random.Range(0.0f, 1.0f) * Mathf.PI * 2;

                float pX = -(Mathf.Cos(randRad) * rX);
                float pY = -(Mathf.Sin(randRad) * rY);

                float cZ = -(meanWh / 2f);

                MapProjectile item = new MapProjectile(AllodsProjectile.Healing, Unit, new HealingProjectileLogic((Unit.Width + Unit.Height) / 2f, pX, pY, cZ, Unit));
                item.ZOffset = -64;
                if (Unit.IsFlying)
                {
                    item.ZOffset += 128;
                }
                item.SetPosition(pX, pY, 0);
                item.ZAbsolute = true;
                MapLogic.Instance.AddObject(item, true);
            }
        }
Exemple #3
0
    public static void SpawnProjectileDirectional(int id, IPlayerPawn source, float x, float y, float z, float tgx, float tgy, float tgz, float speed, MapProjectileCallback cb = null)
    {
        MapProjectile proj = new MapProjectile(id, source, new MapProjectileLogicDirectional(tgx, tgy, tgz, speed), cb);

        proj.SetPosition(x, y, z);
        MapLogic.Instance.Objects.Add(proj);
        // todo notify clients

        if (NetworkManager.IsServer)
        {
            foreach (ServerClient client in ServerManager.Clients)
            {
                if (client.State != ClientState.Playing)
                {
                    continue;
                }

                Player    p         = MapLogic.Instance.GetNetPlayer(client);
                MapObject sourceObj = (MapObject)source;
                if (sourceObj != null)
                {
                    if (!sourceObj.IsVisibleForNetPlayer(p))
                    {
                        ObjectBecameVisible(p, sourceObj); // force keyframe update for source unit
                    }
                }

                ClientCommands.AddProjectileDirectional app;
                app.X          = x;
                app.Y          = y;
                app.Z          = z;
                app.TargetX    = tgx;
                app.TargetY    = tgy;
                app.TargetZ    = tgz;
                app.SourceType = (sourceObj != null) ? sourceObj.GetObjectType() : MapObjectType.Object;

                if (app.SourceType == MapObjectType.Human ||
                    app.SourceType == MapObjectType.Monster)
                {
                    app.SourceTag = ((MapUnit)sourceObj).Tag;
                }
                else if (app.SourceType == MapObjectType.Structure)
                {
                    app.SourceTag = ((MapStructure)sourceObj).Tag;
                }
                else
                {
                    app.SourceTag = -1;
                }

                app.Speed  = speed;
                app.TypeID = id;

                client.SendCommand(app);
            }
        }
    }
Exemple #4
0
    public static void SpawnProjectileEOT(int id, IPlayerPawn source, float x, float y, float z, int duration, int frequency, int startframes = 0, int endframes = 0, int zoffs = -128, MapProjectileCallback cb = null)
    {
        MapProjectile proj = new MapProjectile(id, source, new MapProjectileLogicEOT(duration, frequency, startframes, endframes), cb);

        proj.ZOffset = zoffs;
        proj.SetPosition(x, y, z);
        MapLogic.Instance.Objects.Add(proj);

        if (NetworkManager.IsServer)
        {
            foreach (ServerClient client in ServerManager.Clients)
            {
                if (client.State != ClientState.Playing)
                {
                    continue;
                }

                Player    p         = MapLogic.Instance.GetNetPlayer(client);
                MapObject sourceObj = (MapObject)source;
                if (sourceObj != null)
                {
                    if (!sourceObj.IsVisibleForNetPlayer(p))
                    {
                        ObjectBecameVisible(p, sourceObj); // force keyframe update for source unit
                    }
                }

                ClientCommands.AddProjectileEOT app;
                app.X          = x;
                app.Y          = y;
                app.Z          = z;
                app.SourceType = (sourceObj != null) ? sourceObj.GetObjectType() : MapObjectType.Object;

                if (app.SourceType == MapObjectType.Human ||
                    app.SourceType == MapObjectType.Monster)
                {
                    app.SourceTag = ((MapUnit)sourceObj).Tag;
                }
                else if (app.SourceType == MapObjectType.Structure)
                {
                    app.SourceTag = ((MapStructure)sourceObj).Tag;
                }
                else
                {
                    app.SourceTag = -1;
                }

                app.TypeID      = id;
                app.Duration    = duration;
                app.StartFrames = startframes;
                app.EndFrames   = endframes;
                app.ZOffset     = zoffs;

                client.SendCommand(app);
            }
        }
    }
Exemple #5
0
    public static void SpawnProjectileSimple(int id, IPlayerPawn source, float x, float y, float z, float animspeed = 0.5f, float scale = 1f, int start = 0, int end = 0)
    {
        MapProjectile proj = new MapProjectile(id, source, new MapProjectileLogicSimple(animspeed, scale, start, end), null); // this is usually SFX like stuff. projectile plays animation based on typeid and stops.

        proj.SetPosition(x, y, z);
        MapLogic.Instance.Objects.Add(proj);

        if (NetworkManager.IsServer)
        {
            foreach (ServerClient client in ServerManager.Clients)
            {
                if (client.State != ClientState.Playing)
                {
                    continue;
                }

                Player    p         = MapLogic.Instance.GetNetPlayer(client);
                MapObject sourceObj = (MapObject)source;
                if (sourceObj != null)
                {
                    if (!sourceObj.IsVisibleForNetPlayer(p))
                    {
                        ObjectBecameVisible(p, sourceObj); // force keyframe update for source unit
                    }
                }

                ClientCommands.AddProjectileSimple app;
                app.X          = x;
                app.Y          = y;
                app.Z          = z;
                app.SourceType = (sourceObj != null) ? sourceObj.GetObjectType() : MapObjectType.Object;

                if (app.SourceType == MapObjectType.Human ||
                    app.SourceType == MapObjectType.Monster)
                {
                    app.SourceTag = ((MapUnit)sourceObj).Tag;
                }
                else if (app.SourceType == MapObjectType.Structure)
                {
                    app.SourceTag = ((MapStructure)sourceObj).Tag;
                }
                else
                {
                    app.SourceTag = -1;
                }

                app.TypeID    = id;
                app.AnimSpeed = animspeed;
                app.Scale     = scale;
                app.Start     = start;
                app.End       = end;

                client.SendCommand(app);
            }
        }
    }
Exemple #6
0
    public static void SpawnProjectileLightning(IPlayerPawn source, float x, float y, float z, MapUnit target, int color, MapProjectileCallback cb = null)
    {
        MapProjectile proj = new MapProjectile(AllodsProjectile.Lightning, source, new MapProjectileLogicLightning(target, color), cb);

        proj.SetPosition(x, y, z);
        MapLogic.Instance.Objects.Add(proj);

        if (NetworkManager.IsServer)
        {
            foreach (ServerClient client in ServerManager.Clients)
            {
                if (client.State != ClientState.Playing)
                {
                    continue;
                }

                Player    p         = MapLogic.Instance.GetNetPlayer(client);
                MapObject sourceObj = (MapObject)source;
                if (sourceObj != null)
                {
                    if (!sourceObj.IsVisibleForNetPlayer(p))
                    {
                        ObjectBecameVisible(p, sourceObj); // force keyframe update for source unit
                    }
                }

                ClientCommands.AddProjectileLightning app;
                app.X          = x;
                app.Y          = y;
                app.Z          = z;
                app.SourceType = (sourceObj != null) ? sourceObj.GetObjectType() : MapObjectType.Object;

                if (app.SourceType == MapObjectType.Human ||
                    app.SourceType == MapObjectType.Monster)
                {
                    app.SourceTag = ((MapUnit)sourceObj).Tag;
                }
                else if (app.SourceType == MapObjectType.Structure)
                {
                    app.SourceTag = ((MapStructure)sourceObj).Tag;
                }
                else
                {
                    app.SourceTag = -1;
                }

                app.TargetTag = target.Tag;
                app.Color     = color;

                client.SendCommand(app);
            }
        }
    }
Exemple #7
0
    public bool Update()
    {
        if (Projectile.Class == null)
        {
            return(false);
        }
        // magic handling: blizzard projectile uses frame 8 for real projectile, and 0-7 for death anim
        if (Projectile.Class.ID == (int)AllodsProjectile.Blizzard)
        {
            Projectile.CurrentFrame = 8;
        }
        else if (Projectile.Class.ID == 7) // bat_sonic attack
        {
            Projectile.LightLevel = 0;
        }
        else
        {
            Projectile.LightLevel = 256;
        }
        Vector3 targetCenter = new Vector3(TargetX, TargetY, TargetZ);

        Projectile.Angle = MapObject.FaceVector(targetCenter.x - Projectile.ProjectileX, targetCenter.y - Projectile.ProjectileY);
        Vector3 dir = new Vector3(targetCenter.x - Projectile.ProjectileX, targetCenter.y - Projectile.ProjectileY, targetCenter.z - Projectile.ProjectileZ);

        dir.Normalize();
        dir *= Speed / 20;
        Vector3 newPos = new Vector3(Projectile.ProjectileX + dir.x, Projectile.ProjectileY + dir.y, Projectile.ProjectileZ + dir.z);

        if (Projectile.ProjectileX != targetCenter.x ||
            Projectile.ProjectileY != targetCenter.y ||
            Projectile.ProjectileZ != targetCenter.z)
        {
            bool done = false;
            if ((new Vector3(Projectile.ProjectileX, Projectile.ProjectileY, Projectile.ProjectileZ) - targetCenter).magnitude <= 0.01f ||
                Math.Sign(targetCenter.x - newPos.x) != Math.Sign(targetCenter.x - Projectile.ProjectileX) ||
                Math.Sign(targetCenter.y - newPos.y) != Math.Sign(targetCenter.y - Projectile.ProjectileY) ||
                Math.Sign(targetCenter.z - newPos.z) != Math.Sign(targetCenter.z - Projectile.ProjectileZ))
            {
                newPos.x = targetCenter.x;
                newPos.y = targetCenter.y;
                newPos.z = targetCenter.z;
                done     = true;
            }

            Projectile.SetPosition(newPos.x, newPos.y, newPos.z);
            return(!done);
        }
        else
        {
            // flight done! call the callback and delete the projectile.
            return(false);
        }
    }
Exemple #8
0
        public override void Process()
        {
            Timer++;
            float zatUnit = MapLogic.Instance.GetHeightAt(Unit.X + Unit.FracX + (float)Unit.Width / 2,
                                                          Unit.Y + Unit.FracY + (float)Unit.Height / 2,
                                                          Unit.Width, Unit.Height) / 32;
            float   heightOffset = Mathf.Max(1, ((Unit.Width + Unit.Height) / 4f));
            float   shieldRadius = 0.5f * Mathf.Max(1, ((Unit.Width + Unit.Height) / 2f));
            float   shieldHeight = 0.6f * heightOffset;
            Vector3 initialPos   = new Vector3(Unit.X + Unit.FracX + Unit.Width / 2f, Unit.Y + Unit.FracY + Unit.Height / 2f, 0.1f * heightOffset + zatUnit);

            for (int j = 0; j < 2; j++)
            {
                for (int i = 0; i < Scalar * 16; i++)
                {
                    MapProjectile item        = Grid[i + Scalar * 16 * j];
                    Vector3       particlePos = new Vector3(0, 0, 1);
                    Vector3       pos         = Quaternion.Euler(0, 0, Timer * 2 + 90 * j) * Quaternion.Euler(0, i * 360 / (Scalar * 16), 0) * particlePos;
                    item.SetPosition(pos.x * shieldRadius + initialPos.x, pos.y * shieldRadius + initialPos.y, pos.z * shieldHeight + initialPos.z);
                    item.ZOffset = -64;
                    if (Unit.IsFlying)
                    {
                        item.ZOffset += 128;
                    }
                    item.CurrentFrame = 2 + Mathf.RoundToInt((1f - Mathf.Abs(pos.z)) * 2);
                    item.ZAbsolute    = true;
                    item.DoUpdateView = true;
                }
            }
            for (int j = 0; j < 2; j++)
            {
                for (int i = 0; i < Scalar * 16; i++)
                {
                    MapProjectile item        = Circles[i + Scalar * 16 * j];
                    Vector3       particlePos = new Vector3(0, 1, 0);
                    Vector3       pos         = Quaternion.Euler(0, 0, i * 360 / (Scalar * 16)) * Quaternion.Euler(Timer * 2 + 180 * j, 0, 0) * particlePos;
                    item.SetPosition(pos.x * shieldRadius + initialPos.x, pos.y * shieldRadius + initialPos.y, pos.z * shieldHeight + initialPos.z);
                    item.ZOffset = -64;
                    if (Unit.IsFlying)
                    {
                        item.ZOffset += 128;
                    }
                    item.CurrentFrame = 2 + Mathf.RoundToInt((1f - Mathf.Abs(pos.z)) * 2);
                    item.ZAbsolute    = true;
                    item.DoUpdateView = true;
                }
            }
        }
Exemple #9
0
            public bool Update()
            {
                float cX      = Unit.X + Unit.FracX + Unit.Width / 2f;
                float cY      = Unit.Y + Unit.FracY + Unit.Height / 2f;
                float zatUnit = MapLogic.Instance.GetHeightAt(Unit.X + Unit.FracX + (float)Unit.Width / 2,
                                                              Unit.Y + Unit.FracY + (float)Unit.Height / 2,
                                                              Unit.Width, Unit.Height) / 32;

                Frac += 5f / MapLogic.TICRATE;
                Projectile.SetPosition(cX + X, cY + Y, zatUnit + Z + Frac * Height);
                Projectile.CurrentFrame = Math.Min(7, (int)(Frac * 8));
                if (Frac > 1f)
                {
                    return(false);
                }
                return(true);
            }
Exemple #10
0
    public virtual bool Update()
    {
        // calculate target direction!
        // check if target is gone
        if (!Target.IsAlive || !Target.IsLinked)
        {
            Target = null;
        }

        if (Target != null)
        {
            // special magic for lightning
            Projectile.LightLevel = 256;
            Vector2 targetCenter = new Vector2(Target.X + (float)Target.Width / 2 + Target.FracX, Target.Y + (float)Target.Height / 2 + Target.FracY);
            Projectile.Angle = MapObject.FaceVector(targetCenter.x - Projectile.ProjectileX, targetCenter.y - Projectile.ProjectileY);
            Vector2 dir = new Vector2(targetCenter.x - Projectile.ProjectileX, targetCenter.y - Projectile.ProjectileY);
            dir.Normalize();
            //dir /= 5;
            dir *= Speed / 20;
            Vector2 newPos = new Vector2(Projectile.ProjectileX + dir.x, Projectile.ProjectileY + dir.y);
            if (Projectile.ProjectileX != targetCenter.x ||
                Projectile.ProjectileY != targetCenter.y)
            {
                if (Math.Sign(targetCenter.x - newPos.x) != Math.Sign(targetCenter.x - Projectile.ProjectileX))
                {
                    newPos.x = targetCenter.x;
                }
                if (Math.Sign(targetCenter.y - newPos.y) != Math.Sign(targetCenter.y - Projectile.ProjectileY))
                {
                    newPos.y = targetCenter.y;
                }
                Projectile.SetPosition(newPos.x, newPos.y, Projectile.ProjectileZ);
                return(true);
            }
            else
            {
                // flight done! call the callback and delete the projectile.
                return(false);
            }
        }

        return(false);
    }
Exemple #11
0
    public bool Update()
    {
        Vector3 targetCenter = new Vector3(TargetX, TargetY, TargetZ);

        Projectile.Angle = MapObject.FaceVector(targetCenter.x - Projectile.ProjectileX, targetCenter.y - Projectile.ProjectileY);
        Vector3 dir = new Vector3(targetCenter.x - Projectile.ProjectileX, targetCenter.y - Projectile.ProjectileY, targetCenter.z - Projectile.ProjectileZ);

        dir.Normalize();
        dir *= Speed / 20;
        Vector3 newPos = new Vector3(Projectile.ProjectileX + dir.x, Projectile.ProjectileY + dir.y, Projectile.ProjectileZ + dir.z);

        if (Projectile.ProjectileX != targetCenter.x ||
            Projectile.ProjectileY != targetCenter.y ||
            Projectile.ProjectileZ != targetCenter.z)
        {
            bool done = false;
            if ((new Vector3(Projectile.ProjectileX, Projectile.ProjectileY, Projectile.ProjectileZ) - targetCenter).magnitude <= 0.01f ||
                Math.Sign(targetCenter.x - newPos.x) != Math.Sign(targetCenter.x - Projectile.ProjectileX) ||
                Math.Sign(targetCenter.y - newPos.y) != Math.Sign(targetCenter.y - Projectile.ProjectileY) ||
                Math.Sign(targetCenter.z - newPos.z) != Math.Sign(targetCenter.z - Projectile.ProjectileZ))
            {
                newPos.x = targetCenter.x;
                newPos.y = targetCenter.y;
                newPos.z = targetCenter.z;
                done     = true;
            }

            Projectile.SetPosition(newPos.x, newPos.y, newPos.z);
            return(!done);
        }
        else
        {
            // flight done! call the callback and delete the projectile.
            return(false);
        }
    }
Exemple #12
0
    public virtual bool Update()
    {
        // calculate target direction!
        // check if target is gone
        if (Target != null && (!Target.IsAlive || !Target.IsLinked))
        {
            Target = null;
        }

        Projectile.Alpha = 0;

        if (Target != null && SubProjectiles.Count <= 0)
        {
            // special magic for lightning
            Projectile.LightLevel = 256;
            TargetCenter          = new Vector2(Target.X + (float)Target.Width / 2 + Target.FracX, Target.Y + (float)Target.Height / 2 + Target.FracY);
            TargetAngle           = Projectile.Angle = MapObject.FaceVector(TargetCenter.x - Projectile.ProjectileX, TargetCenter.y - Projectile.ProjectileY);
            TargetDir             = new Vector2(TargetCenter.x - Projectile.ProjectileX, TargetCenter.y - Projectile.ProjectileY);
            TargetDst             = TargetDir.magnitude;
            TargetDir.Normalize();
            // spawn projectiles along the way
            Density = 0.2f;
            for (float i = 0; i < TargetDst; i += Density)
            {
                MapProjectile visProj = new MapProjectile(Color == 0 ? AllodsProjectile.Lightning : AllodsProjectile.ChainLightning);
                visProj.LightLevel   = 0;
                visProj.CurrentFrame = Color == 0 ? 0 : (5 * (Color - 1));
                visProj.SetPosition(Projectile.ProjectileX + TargetDir.x * i, Projectile.ProjectileY + TargetDir.y * i, 0); // for now
                MapLogic.Instance.Objects.Add(visProj);
                SubProjectiles.Add(visProj);
            }

            Projectile.CallCallback();
        }

        AnimTime += 0.08f;

        float   hUDiff     = MapLogic.Instance.GetHeightAt(TargetCenter.x, TargetCenter.y, 1, 1) / 32f;
        float   htOrig     = MapLogic.Instance.GetHeightAt(Projectile.ProjectileX, Projectile.ProjectileY, 1, 1) / 32f;
        float   angleToDst = Mathf.Atan2(TargetDir.y, TargetDir.x);
        float   sinScale   = TargetDst / 8 * Mathf.Sin((float)MapLogic.Instance.LevelTime / 2 * TargetDst);
        Vector2 offs       = new Vector2(0, 1);
        float   sinX       = Mathf.Cos(angleToDst) * offs.x - Mathf.Sin(angleToDst) * offs.y;
        float   sinY       = Mathf.Cos(angleToDst) * offs.y + Mathf.Sin(angleToDst) * offs.x;

        for (int i = 0; i < SubProjectiles.Count; i++)
        {
            float idst = Density * i;
            // get angle from first to second. calculate sin wave
            float baseX = Projectile.ProjectileX + TargetDir.x * idst;
            float baseY = Projectile.ProjectileY + TargetDir.y * idst;

            float         sscale = (Sin10(idst / TargetDst) * sinScale);
            MapProjectile sub    = SubProjectiles[i];
            int           cframe = (Color == 0 ? 0 : (5 * (Color - 1)));
            sub.CurrentFrame = (int)(cframe + 4 * AnimTime);
            sub.LightLevel   = 0;
            if (i % 12 == 0)
            {
                sub.LightLevel = (int)(512 * (1f - AnimTime));
            }
            float htDiff = MapLogic.Instance.GetHeightAt(baseX + sinX * sscale, baseY + sinY * sscale, 1, 1) / 32f;
            float lval   = (float)i / SubProjectiles.Count;
            float htLerp = hUDiff * lval + htOrig * (1f - lval);

            sub.SetPosition(baseX + sinX * sscale, baseY + sinY * sscale, -htDiff + htLerp);
        }

        if (AnimTime > 1)
        {
            foreach (MapProjectile sub in SubProjectiles)
            {
                sub.Dispose();
            }

            Projectile.Dispose();
            return(false);
        }

        return(true);
    }
Exemple #13
0
        public override void Process()
        {
            if (Unit.Flags != LastFlags)
            {
                UnitFlags leftFlags = Unit.Flags;

                // remove unused projectiles
                for (int i = 0; i < Indicators.Count; i++)
                {
                    UnitFlags flag = 0;
                    switch (Indicators[i].ClassID)
                    {
                    case AllodsProjectile.ProtectionFire:
                        flag = UnitFlags.ProtectionFire;
                        break;

                    case AllodsProjectile.ProtectionWater:
                        flag = UnitFlags.ProtectionWater;
                        break;

                    case AllodsProjectile.ProtectionAir:
                        flag = UnitFlags.ProtectionAir;
                        break;

                    case AllodsProjectile.ProtectionEarth:
                        flag = UnitFlags.ProtectionEarth;
                        break;
                    }

                    if ((Unit.Flags & flag) == 0)
                    {
                        Indicators[i].Dispose();
                        i--;
                        continue;
                    }
                    else
                    {
                        leftFlags &= ~flag;
                    }
                }

                if (leftFlags.HasFlag(UnitFlags.ProtectionAir))
                {
                    CreateProjectile(AllodsProjectile.ProtectionAir);
                }
                if (leftFlags.HasFlag(UnitFlags.ProtectionWater))
                {
                    CreateProjectile(AllodsProjectile.ProtectionWater);
                }
                if (leftFlags.HasFlag(UnitFlags.ProtectionEarth))
                {
                    CreateProjectile(AllodsProjectile.ProtectionEarth);
                }
                if (leftFlags.HasFlag(UnitFlags.ProtectionFire))
                {
                    CreateProjectile(AllodsProjectile.ProtectionFire);
                }
                LastFlags = Unit.Flags;
            }

            for (int i = 0; i < Indicators.Count; i++)
            {
                float         indicatorAngle = (Mathf.PI * 2) / Indicators.Count * i + Mathf.PI * 0.5f;
                MapProjectile p = Indicators[i];

                float pX = -Mathf.Cos(indicatorAngle) * 0.25f;
                float pY = Mathf.Sin(indicatorAngle) * 0.25f;

                if (Indicators.Count == 1)
                {
                    pY = -pY;
                }

                float pZ = MapLogic.Instance.GetHeightAt(Unit.X + Unit.FracX, Unit.Y + Unit.FracY, Unit.Width, Unit.Height) / 32
                           + (1f + (((Unit.Width + Unit.Height) / 2f) - 1f) / 2f);

                p.Alpha = (Unit.GetVisibility() == 2) ? 1f : 0;
                p.SetPosition(Unit.X + Unit.FracX + Unit.Width / 2f + pX, Unit.Y + Unit.FracY + Unit.Height / 2f + pY, pZ);
                p.ZAbsolute = true;
                p.ZOffset   = -32;
                if (Unit.IsFlying)
                {
                    p.ZOffset += 128;
                }
                p.CurrentFrame = (p.CurrentFrame + 1) % p.Class.Phases;
                p.DoUpdateView = true;
            }
        }