protected override void OnUpdate()
    {
        Entities.WithAll <Transform, ActorInventory, ActorInput>().ForEach((Entity inventoryEntity, Transform inventoryTransform, ref ActorInventory actorInventory, ref ActorInput actorInput) =>
        {
            newActorInventory      = actorInventory;
            newInventoryActorInput = actorInput;
            attemptToPickUp        = false;

            if (actorInput.actionToDo == 1 && actorInput.action == 0)
            {
                Entities.WithAll <Transform, ActorItem>().ForEach((Entity itemEntity, Transform itemTransform) =>
                {
                    //Get Item shared component
                    var actorItem = EntityManager.GetSharedComponentData <ActorItem>(itemEntity);

                    //Check if were in distance and not already picked up
                    if (!attemptToPickUp && Vector3.Distance(inventoryTransform.position, itemTransform.position) <= 1f && !EntityManager.HasComponent(itemEntity, typeof(Parent)))
                    {
                        //Set that we attempted to pick a item up
                        attemptToPickUp = true;

                        //Get Target Socket
                        var targetSocket = ActorUtilities.GetFirstEmptyTransform(inventoryTransform, actorItem.sockets);

                        //Do Pickup | Set action to 0
                        if (targetSocket != null)
                        {
                            ActorUtilities.PickupItem(PostUpdateCommands, EntityManager, targetSocket, itemTransform, itemEntity, actorItem, inventoryTransform, inventoryEntity, ref newActorInventory);
                            newInventoryActorInput.action = 0;
                        }
                    }
                });
            }

            //Drop | Set Action to 0
            if (actorInput.actionToDo == 1 && actorInput.action == 0 && attemptToPickUp == false && newActorInventory.isEquipped == 1)
            {
                ActorUtilities.DropItem(PostUpdateCommands, EntityManager, newActorInventory.equippedEntiy, inventoryTransform, inventoryEntity, ref newActorInventory);
                newInventoryActorInput.action = 0;
            }

            actorInventory = newActorInventory;
            actorInput     = newInventoryActorInput;
        });
    }
Esempio n. 2
0
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        Main m = GetNode <Main>("/root/main");

        _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");

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

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

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


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

        // Add weapons
        _inventory.AddWeapon(AttackFactory.CreatePlayerShotgun(_head, _body));
        _inventory.AddWeapon(AttackFactory.CreateStakegun(_head, _body));

        m.cam.AttachToTarget(_head);
    }
Esempio n. 3
0
 //private Methods
 private void AddActorComponents()
 {
     m_Abilities = (gameObject.GetComponent <ActorAbilities>() == null ? gameObject.AddComponent <ActorAbilities>() : gameObject.GetComponent <ActorAbilities>());
     m_Movement  = (gameObject.GetComponent <ActorMovement>() == null ? gameObject.AddComponent <ActorMovement>() : gameObject.GetComponent <ActorMovement>());
     m_Inventory = (gameObject.GetComponent <ActorInventory>() == null ? gameObject.AddComponent <ActorInventory>() : gameObject.GetComponent <ActorInventory>());
 }
Esempio n. 4
0
    public static void DropItem(EntityCommandBuffer postUpdateCommands, EntityManager entityManager, Entity itemEntity, Transform inventoryTransform, Entity inventoryEntity, ref ActorInventory actorInventory)
    {
        //Item is no longer parent of a entity
        postUpdateCommands.RemoveComponent(actorInventory.equippedEntiy, typeof(Parent));

        //Rest transform parent, physics and collision
        var itemTransform = entityManager.GetComponentObject <Transform>(actorInventory.equippedEntiy);

        itemTransform.GetComponent <Rigidbody>().useGravity  = true;
        itemTransform.GetComponent <Rigidbody>().isKinematic = false;
        itemTransform.GetComponent <Collider>().enabled      = true;
        itemTransform.SetParent(null, true);

        //Were dropping main entity
        if (actorInventory.equippedEntiy == itemEntity)
        {
            actorInventory.isEquipped = 0;
            inventoryTransform.GetComponentInChildren <Animator>().SetFloat("itemType", 0.0f);
            if (entityManager.HasComponent(inventoryEntity, typeof(ActorTagCanMeleeAttack)))
            {
                postUpdateCommands.RemoveComponent <ActorTagCanMeleeAttack>(inventoryEntity);
            }
        }
    }
Esempio n. 5
0
    public static void PickupItem(EntityCommandBuffer postUpdateCommands, EntityManager entityManager, Transform socket, Transform itemTransform, Entity itemEntity, ActorItem actorItem, Transform inventoryTransform, Entity inventoryEntity, ref ActorInventory inventory)
    {
        //Get Index of socket
        var targetSocketIndex = 0;

        //Get Index of targt socket
        for (int i = 0; i < actorItem.sockets.Length; i++)
        {
            if (actorItem.sockets[i] == socket.name)
            {
                targetSocketIndex = i;
                break;
            }
        }


        //Add Parent tag to item
        postUpdateCommands.AddComponent(itemEntity, new Parent());

        //Disable Physics | Collision
        itemTransform.GetComponent <Rigidbody>().useGravity  = false;
        itemTransform.GetComponent <Rigidbody>().isKinematic = true;
        itemTransform.GetComponent <Collider>().enabled      = false;

        //Set Parent | local position | local euelr angle
        itemTransform.parent           = socket;
        itemTransform.localPosition    = actorItem.socketOffsetPositions[targetSocketIndex];
        itemTransform.localEulerAngles = actorItem.socketEulerAngles[targetSocketIndex];

        //Set inventory equped entity | Mark if actor can melee attack ?
        if (actorItem.socketIsMain[targetSocketIndex])
        {
            inventory.equippedEntiy = itemEntity;
            inventory.isEquipped    = 1;


            inventoryTransform.GetComponentInChildren <Animator>().SetFloat("itemType", actorItem.itemAnimationIndex);

            if (entityManager.HasComponent <ActorMeleeWeapon>(itemEntity) && !entityManager.HasComponent <ActorTagCanMeleeAttack>(inventoryEntity))
            {
                postUpdateCommands.AddComponent(inventoryEntity, new ActorTagCanMeleeAttack());
            }
        }
    }
Esempio n. 6
0
	//private Methods
	private void AddActorComponents()
	{
		m_Abilities = (gameObject.GetComponent<ActorAbilities>() == null ? gameObject.AddComponent<ActorAbilities>() : gameObject.GetComponent<ActorAbilities>());
		m_Movement = (gameObject.GetComponent<ActorMovement>() == null ? gameObject.AddComponent<ActorMovement>() : gameObject.GetComponent<ActorMovement>());
		m_Inventory = (gameObject.GetComponent<ActorInventory>() == null ? gameObject.AddComponent<ActorInventory>() : gameObject.GetComponent<ActorInventory>());
	}
Esempio n. 7
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);
    }