Пример #1
0
        public void ProcessMouseMotion(InputEventMouseMotion motion, Vector2 screenRatio)
        {
            float sensitivity = MOUSE_SENSITIVITY;

            Vector2 ratio      = ZqfGodotUtils.GetWindowToScreenRatio();
            float   mouseMoveX = motion.Relative.x * sensitivity * ratio.x;

            // flip as we want moving mouse to the right to rotate left
            mouseMoveX = -mouseMoveX;
            _yaw      += mouseMoveX;

            float mouseMoveY = motion.Relative.y * sensitivity * ratio.y;

            _pitch += mouseMoveY;
        }
Пример #2
0
        public void Spawn(Vector3 origin, Vector3 dir)
        {
            _dead = false;
            //_tick = 1;
            Particles p = GetNode <Particles>("Particles");

            p.Emitting = true;
            _tick      = p.Lifetime;

            RotationDegrees = ZqfGodotUtils.CalcEulerDegrees(-dir);

            Transform t = GlobalTransform;

            t.origin        = origin;
            GlobalTransform = t;
        }
Пример #3
0
        private void SpawnChild()
        {
            EntMob mob = Main.i.factory.SpawnMob(mobType);

            if (mob == null)
            {
                Console.WriteLine($"BulkSpawner - failed to spawn child - disabling");
                isSpawning = false;
                return;
            }
            ZqfGodotUtils.Teleport(mob, GlobalTransform.origin);
            mob.ParentActorId = _entId;
            _numLiveChildren++;
            _tick = 2;
            Console.WriteLine($"Bulk spawned mob {mob.actorId} parent {mob.ParentActorId}");
        }
Пример #4
0
        public override void _Ready()
        {
            _model  = ZqfGodotUtils.GetNodeSafe <MeshInstance>(this, "mlrs_turret/Cube");
            _body   = ZqfGodotUtils.GetNodeSafe <RigidBody>(this, "mlrs_turret");
            _hpArea = ZqfGodotUtils.GetNodeSafe <Health>(this, "mlrs_turret/area");
            if (_hpArea != null)
            {
                _hpArea.SetCallbacks(OnHealthChange, OnDeath);
                _hpArea.OverrideStats(Team.Mobs, 400, 400);
            }

            _idleLocalTransform = Transform;

            _prjDef            = new ProjectileDef();
            _prjDef.damage     = 10;
            _prjDef.prefabPath = GameFactory.Path_PointProjectile;

            _prjDef.speedMode   = ProjectileDef.SpeedMode.Basic;
            _prjDef.launchSpeed = 15;

            //_prjDef.moveMode = ProjectileDef.MoveMode.Accel;
            //_prjDef.launchSpeed = 100;
            //_prjDef.maxSpeed = 100;
            //_prjDef.minSpeed = 10;
            //_prjDef.accelPerSecond = -300;

            _patternDef             = new PatternDef();
            _patternDef.count       = 8;
            _patternDef.patternType = PatternType.HorizontalLine;
            _patternDef.scale       = new Vector3(4, 4, 0);

            _transforms = new List <Transform>(_patternDef.count);

            IActor actorParent = Game.DescendTreeToActor(this);

            if (actorParent != null)
            {
                Console.WriteLine($"Turret found parent actor {actorParent.actorId}");
            }
        }
Пример #5
0
        virtual public void FirePrimary()
        {
            if (_primaryPrjDef == null)
            {
                return;
            }
            Transform t = _launchNode.GlobalTransform;

            ZqfGodotUtils.FillSpreadAngles(t, _primarySpread, 2000, 1200);
            for (int i = 0; i < _primarySpread.Count; ++i)
            {
                PointProjectile prj = Main.i.factory.SpawnProjectile(_primaryPrjDef.prefabPath);
                if (prj == null)
                {
                    Console.WriteLine($"Got no prj instance"); return;
                }
                //prj.Launch(_launchNode.GlobalTransform, _primaryPrjDef, _ignoreBody);

                prj.Launch(t.origin, _primarySpread[i], _primaryPrjDef, _ignoreBody);
                _tick = _weaponDef.primaryRefireTime;
            }
        }
Пример #6
0
        virtual public void FireSecondary(AttackSource src)
        {
            if (_secondaryPrjDef == null)
            {
                return;
            }
            Transform t = _launchNode.GlobalTransform;

            ZqfGodotUtils.FillSpreadAngles(
                t, _secondarySpread, _weaponDef.secondarySpread.x, _weaponDef.secondarySpread.y);
            for (int i = 0; i < _secondarySpread.Count; ++i)
            {
                PointProjectile prj = Main.i.factory.SpawnProjectile(_secondaryPrjDef.prefabPath);
                if (prj == null)
                {
                    Console.WriteLine($"Got no prj instance"); return;
                }
                //prj.Launch(_launchNode.GlobalTransform, _primaryPrjDef, _ignoreBody);

                prj.Launch(t.origin, _secondarySpread[i], _secondaryPrjDef, src.ignoreBody, src.team);
                _tick        = _weaponDef.secondaryRefireTime;
                _lastTickMax = _tick;
            }
        }
Пример #7
0
    public PointProjectile SpawnPointProjectile(bool addToTree = true, Node overrideParent = null)
    {
        Node parent = SelectParent(addToTree, overrideParent);

        return(ZqfGodotUtils.CreateInstance <PointProjectile>(Path_PointProjectile, parent));
    }
Пример #8
0
    public EntPlayer SpawnPlayer()
    {
        EntPlayer plyr = ZqfGodotUtils.CreateInstance <EntPlayer>(Path_EntPlayer, _root);

        return(plyr);
    }
Пример #9
0
    public SwordThrowProjectile SpawnThrownSword(bool addToTree = true, Node overrideParent = null)
    {
        Node parent = SelectParent(addToTree, overrideParent);

        return(ZqfGodotUtils.CreateInstance <SwordThrowProjectile>(Path_ThrownSword, parent));
    }
Пример #10
0
    private void MoveAsRay(float delta)
    {
        Transform t = GlobalTransform;

        // apply move effects
        if (_def.speedMode == ProjectileDef.SpeedMode.Accel)
        {
            _speed += _def.accelPerSecond * delta;
            _speed  = ZqfGodotUtils
                      .Capf(_speed, _def.minSpeed, _def.maxSpeed);
        }

        if (_def.guideMode == ProjectileDef.GuideMode.Turn &&
            _targetActorId != Game.NullActorId)
        {
            IActor actor = Main.i.game.GetActor(_targetActorId);
            // TODO lerp rotation toward target
            Transform turnTarget = actor.GetTransformForTarget();
        }

        Vector3 origin  = t.origin;
        Vector3 forward = -t.basis.z;
        Vector3 dest    = origin;

        dest += (forward * _speed) * delta;
        // Set origin back slightly as otherwise rays seem to tunnel
        // (perhaps due to ray starting inside collider...?)
        origin -= (forward * 0.25f);
        uint mask = uint.MaxValue;

        Dictionary hitResult = ZqfGodotUtils.CastRay(this, origin, dest, mask, _ignoreBody);
        bool       spawnGFX  = true;

        // no hits, just move and leave
        if (hitResult.Keys.Count <= 0)
        {
            t.origin        = dest;
            GlobalTransform = t;
            return;
        }

        _touch.hitPos     = (Vector3)hitResult["position"];
        _touch.hitNormal  = (Vector3)hitResult["normal"];
        _touch.damage     = _def.damage;
        _touch.teamId     = _team;
        _touch.touchType  = TouchType.Projectile;
        _touch.damageType = _def.damageType;

        object obj = hitResult["collider"];

        /*
         * IActor actor = Game.ExtractActor(obj);
         * //ITouchable actor = Game.ExtractTouchable(obj);
         * if (actor != null)
         * {
         *      TouchResponseData response = actor.ActorTouch(_touch);
         *      if (response.responseType != TouchResponseType.None)
         *      {
         *              // leave spawning particles to the victim
         *              spawnGFX = false;
         *      }
         * }
         */
        TouchResponseData response = Game.TouchGameObject(_touch, obj);

        if (response.responseType == TouchResponseType.None)
        {
            t.origin        = dest;
            GlobalTransform = t;
            return;
        }
        if (response.responseType != TouchResponseType.None)
        {
            // leave spawning particles to the victim
            spawnGFX = false;
        }

        if (spawnGFX)
        {
            GFXQuick gfx = Main.i.factory.SpawnGFX(impactGFX);
            gfx.Spawn(_touch.hitPos, _touch.hitNormal);
        }
        if (_def.impactDef != null)
        {
            RunImpactDef(_touch.hitPos, _def.impactDef);
        }
        if (_def.destroyMode == ProjectileDef.DestroyMode.Embed)
        {
            _state          = State.Embedded;
            t.origin        = _touch.hitPos;
            _tick           = 3;
            GlobalTransform = t;
        }
        else
        {
            Die();
        }
        return;
    }
Пример #11
0
        public void Tick(float delta, EquippableTickInfo info)
        {
            if (info.secondaryWasOn)
            {
                _mode++;
                if (_mode >= Mode.Last)
                {
                    _mode = Mode.Deathray;
                }
                UpdateDisplayName();
            }
            switch (_mode)
            {
            case Mode.Deathray:
                if (info.primaryOn)
                {
                    FireDeathRayShot(info);
                }
                break;

            case Mode.Spawn:
                if (info.primaryWasOn)
                {
                    if (_aimLaserNode == null)
                    {
                        Console.WriteLine($"Godhand has no aim laser for spawning");
                        break;
                    }
                    Vector3 pos = _aimLaserNode.GlobalTransform.origin;
                    SpawnMob(pos);
                }
                break;

            case Mode.CycleSpawn:
                if (info.primaryWasOn)
                {
                    _mobTypeIndex++;
                    if (_mobTypeIndex >= _mobTypes.Length)
                    {
                        _mobTypeIndex = 0;
                    }
                    UpdateDisplayName();
                }
                break;

            case Mode.DebugTag:
                //_aimActorId
                Transform t      = _launchNode.GlobalTransform;
                Vector3   origin = t.origin;
                Vector3   dest   = origin + (-t.basis.z * 1000);
                Godot.Collections.Dictionary hitDict = ZqfGodotUtils
                                                       .CastRay(_launchNode, origin, dest, uint.MaxValue, info.src.ignoreBody);
                if (hitDict.Keys.Count == 0)
                {
                    _aimActorId = Game.NullActorId;
                    UpdateDisplayName();
                    break;
                }
                IActor actor = Game.ExtractActor(hitDict["collider"]);
                if (actor == null)
                {
                    _aimActorId = Game.NullActorId;
                    UpdateDisplayName();
                    break;
                }
                int newId = actor.actorId;
                // refresh actor Id if required
                if (_aimActorId != newId)
                {
                    _aimActorId = newId;
                    UpdateDisplayName();
                }
                if (info.primaryWasOn)
                {
                    Main.i.game.SetDebugActorId(_aimActorId);
                }
                break;
            }
        }
Пример #12
0
        private void SpawnMob(Vector3 pos)
        {
            EntMob mob = Main.i.factory.SpawnMob(_mobTypes[_mobTypeIndex]);

            ZqfGodotUtils.Teleport(mob, pos);
        }
Пример #13
0
        public void Think(EntMob mob, float delta)
        {
            int stunAccum = mob.stunAccumulator;

            mob.stunAccumulator = 0;
            if (stunAccum >= mob.mobDef.stunThreshold)
            {
                // switch to stun and update with that instead
                _mobThink.ApplyStun(mob);
                _mobThink.UpdateMob(mob, delta);
                return;
            }

            IActor actor = Main.i.game.CheckTarget(mob.targetActorId, mob.GetTeam());

            if (actor == null)
            {
                mob.targetActorId = Game.NullActorId;
                return;
            }
            mob.targetActorId = actor.actorId;
            Transform self   = mob.GetTransformForTarget();
            Vector3   tar    = actor.GetTransformForTarget().origin;
            float     yawDeg = ZqfGodotUtils.FlatYawDegreesBetween(
                self.origin, tar);

            mob.body.RotationDegrees = new Vector3(0, yawDeg + 180, 0);
            self = mob.GetTransformForTarget();
            Vector3 toTar = (tar - self.origin).Normalized();

            if (mob.thinkTick <= 0)
            {
                mob.thinkTick = 1;
                PointProjectile prj = Main.i.factory.SpawnPointProjectile();
                prj.Launch(self.origin, toTar, mob.prjDef, mob.body, Team.Mobs);
            }
            else
            {
                mob.thinkTick -= delta;
            }

            if (mob.moveTick <= 0)
            {
                float rand = ZqfGodotUtils.Randomf();
                float dist = ZqfGodotUtils.Distance(self.origin, tar);
                mob.moveTick = 1.5f;
                // move toward target
                if (dist > mob.mobDef.evadeRange)
                {
                    // randomly jink to the side
                    if (rand < 0.25)
                    {
                        yawDeg += 45;
                    }
                    else if (rand < 0.5)
                    {
                        yawDeg -= 45;
                    }
                    // check movement again in:
                    mob.moveTick = 1f;
                }
                else
                {
                    // evade either left or right
                    // don't add a full 90 degrees as will evade straight out of evade dist
                    yawDeg      += (rand > 0.5) ? 70 : -70;
                    mob.moveTick = 1.5f;
                }
                float radians = Mathf.Deg2Rad(yawDeg);
                mob.lastSelfDir = new Vector3(Mathf.Sin(radians), 0, Mathf.Cos(radians));
            }
            else
            {
                mob.moveTick -= delta;
            }
            //////////////////////////////////////
            // Move

            // calculate self move
            mob.selfMove = FPSController.CalcVelocityQuakeStyle(
                mob.velocity, mob.lastSelfDir, mob.mobDef.walkSpeed, delta, true, mob.mobDef.friction, mob.mobDef.accelForce);

            mob.velocity = mob.selfMove;
            // apply push forces
            mob.velocity       += mob.pushAccumulator;
            mob.pushAccumulator = Vector3.Zero;
            if (mob.velocity.LengthSquared() > Game.MaxActorVelocity * Game.MaxActorVelocity)
            {
                mob.velocity  = mob.velocity.Normalized();
                mob.velocity *= Game.MaxActorVelocity;
            }
            Vector3 result = mob.body.MoveAndSlide(mob.velocity);
        }
Пример #14
0
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        //_main = GetNode<Main>("/root/main");
        _main = Main.i;

        _input = new FPSInput();

        _hudState            = new HUDPlayerState();
        _hudState.health     = 80;
        _hudState.ammoLoaded = 999;
        _hudState.weaponName = "Stakegun";

        // find Godot scene nodes
        _body       = GetNode <KinematicWrapper>("actor_base");
        _body.actor = this;
        _body.HideModels();

        _head        = GetNode <Spatial>("actor_base/head");
        _meleeVolume = _head.GetNode <MeleeHitVolume>("melee_hit_volume");

        ///////////////////////////////////////
        // view models

        // grab hands placeholder and attach it to the head node
        _handsPlaceholder = GetNode <ViewModel>("hands_placeholder");
        Transform t = _handsPlaceholder.GlobalTransform;

        RemoveChild(_handsPlaceholder);
        _head.AddChild(_handsPlaceholder);
        _handsPlaceholder.GlobalTransform = t;
        _handsPlaceholder.SetEnabled(false);

        // same for placeholder gun
        _gunPlaceholder = GetNode <ViewModel>("view_placeholder_gun");
        ZqfGodotUtils.SwapSpatialParent(_gunPlaceholder, _head);
        _gunPlaceholder.SetEnabled(true);
        _viewModel = _gunPlaceholder;

        _laserDot = GetNode <LaserDot>("laser_dot");
        _laserDot.CustomInit(_head, uint.MaxValue, 1000);

        _thrownSword = _main.factory.SpawnThrownSword(false);
        _main.AddOrphanNode(_thrownSword);

        // init components
        _fpsCtrl = new FPSController(_body, _head);


        // Inventory
        _inventory = new ActorInventory();
        _inventory.Init(_head, 1);

        // Add weapons
        SwordThrowProjectile prj = _main.factory.SpawnThrownSword();

        _inventory.AddWeapon(AttackFactory.CreatePlayerMelee(_meleeVolume, prj, _laserDot));
        _inventory.AddWeapon(AttackFactory.CreatePlayerShotgun(_head, _body));
        _inventory.AddWeapon(AttackFactory.CreateStakegun(_head, _body));
        _inventory.AddWeapon(AttackFactory.CreateLauncher(_head, _body));
        _inventory.AddWeapon(new InvWeapGodhand(_head, _laserDot));
        _inventory.SelectWeaponByIndex(1);

        _main.cam.AttachToTarget(_head, Vector3.Zero, GameCamera.ParentType.Player);

        if (_entId == 0)
        {
            // no id previous set, request one
            _entId = _main.game.ReserveActorId(1);
            _main.game.RegisterActor(this);
        }

        _main.Broadcast(GlobalEventType.PlayerSpawned, this);
    }