示例#1
0
 private void DamagePlayer()
 {
     Debug.Log("Enemy: Damage player event");
     Resource_Inventory.RemoveLives(damage_to_player);
     Text_Bubble.CreateTemporaryTextBubble("-" + damage_to_player.ToString(), 3f, transform.position, Color.red);
     DamagePlayerEvent?.Invoke(this, new EnemyV2RefEventArgs(this));
 }
    void OnNodeSelect(object caller, TowerPlaceSelectEventArgs args)
    {
        //Debug.Log("node selected");

        //TODO: Have an actual, nonmagical cost
        //handle placing tower
        //Can only place if there is no tower already present and we are currently trying to place a tower
        if (flag_placement_in_progress)
        {
            if (!args.node.IsOccupied())
            {
                //Debug.Log("placement attempt");
                if (Resource_Inventory.TryTakeResources(tower_to_place.price_list))
                {
                    RemoveGhostFade();

                    Tower_V2 tower_instance = Instantiate(tower_to_place, new Vector3(0, 0, 0), Quaternion.identity);
                    //if the node can't attach the new tower instance, we destroy it
                    if (!args.node.TryAttachTower(tower_instance))
                    {
                        //Debug.Log("placement attempt failed! destroying instance...");
                        Destroy(tower_instance);
                    }
                    else
                    {
                        //Debug.Log("placement attempt successful!");
                        EndTowerPlacement();
                    }

                    TowerPlacedEvent?.Invoke(this, new TowerV2RefEventArgs(tower_instance));
                }
                else
                {
                    //Write tower construction failed! code here.
                    //Text bubble explains why placement cant happen. Make sure this isnt spammable!?

                    Text_Bubble.CreateTemporaryTextBubble("Not enough resources!", info_bubble_duration, args.node.gameObject.transform.position);
                }
            }
            else
            {
                //TODO: Tower failed! reason: space is already occupied!
                Text_Bubble.CreateTemporaryTextBubble("Space occuupied!", info_bubble_duration, args.node.gameObject.transform.position);
            }
        }
    }
示例#3
0
    //TODO: Develop a better strategy for reducing the number of resources returned upon refund. it's currently a magic number...
    private void RefundResources()
    {
        List <Resource_Attributes> refund_ras = new List <Resource_Attributes>();

        foreach (Resource_Attributes ra in price_list)
        {
            Resource_Attributes ra_to_add = gameObject.AddComponent <Resource_Attributes>();
            ra_to_add.resource_amount = ra.resource_amount;
            ra_to_add.resource_type   = ra.resource_type;

            ra_to_add.resource_amount = (int)(ra_to_add.resource_amount * .75f);

            refund_ras.Add(ra_to_add);
        }

        Resource_Inventory.AddResourcesToInventory(refund_ras);
    }
 //TODO:
 //[DONE?] Display ghost tower on mouse enter IFF flag_placement_in_progress
 //[DONE?] Provide contextual hint (blue / red) showing if tower is legally placeable at the Node
 //Need: Node Occupied status, current resource amount.
 //TODO:  Must continue to update current resource amount and check to see if we need to change from red to blue
 //  Can change to a continuecheckforresources coroutine or something that ends at the other stop conds in this listener impl
 void OnNodeMouseEnter(object caller, TowerPlaceSelectEventArgs args)
 {
     //Decision tree of ghost rendering, Might be better to handle differently but this works for now
     if (flag_placement_in_progress)
     {
         if (args.node.IsOccupied())
         {
             RenderGhostRed(args.position.position); //oops... we're going to have to live with this transform "position" mislabel for now...
         }
         else
         {
             if (Resource_Inventory.CheckResourcesAvailable(tower_to_place.price_list))
             {
                 RenderGhostBlue(args.position.position);
             }
             else
             {
                 RenderGhostRed(args.position.position);
             }
         }
     }
 }