private bool GetCBFromCollider(Collider col, out CollectibleBehavior cb)
        {
            cb = col.GetComponent <CollectibleBehavior>();
            if (cb == null)
            {
                cb = col.GetComponentInChildren <CollectibleBehavior>();
            }
            else
            {
                return(true);
            }

            if (cb == null)
            {
                cb = col.GetComponentInParent <CollectibleBehavior>();
            }
            else
            {
                return(true);
            }

            if (cb != null)
            {
                return(true);
            }

            Debug.LogWarning("Objected tagged as Collectible w/o CollectibleBehaviour attached");
            return(false);
        }
Esempio n. 2
0
    // Update is called once per frame


    public void AddSingleSound(CollectibleBehavior src)
    {
        if (isPlaying)
        {
            return;
        }
        if (isRecordingSolo)
        {
            return;
        }

        Sound s;

        s.timeStamp     = 0;
        s.audioClip     = src.m_audioSource.clip;
        s.lengthInBeats = src.lengthInBeats;

        SoundAction a = new SoundAction();

        a.type        = 0;
        a.singleSound = s;

        composition.Add(a);
        Debug.Log("Stored a single sound");
    }
Esempio n. 3
0
    public CollectibleBehavior AttachAbilityTo(GameObject objectToAttachTo)
    {
        CollectibleBehavior behaviorComponent = GetBehaviorComponent(objectToAttachTo);

        behaviorComponent.Config = this;
        behavior = behaviorComponent;
        return(behavior);
    }
        private void ActivateWaggleDance()
        {
            if (waggleCollected <= 0)
            {
                return;
            }

            bool didDance = false;

            if (curTarget != null)
            {
                if (curTarget.CompareTag("Enemy"))
                {
                    // This currently just feels like a different version of the free sting...
                    Debug.Log("here: " + curTarget.name);
                    FindObjectOfType <StingBehavior>().FinishSting(1, 1, curTarget);
                    didDance = true;
                }
                else if (curTarget.CompareTag("Collectible"))
                {
                    CollectibleBehavior cb = curTarget.GetComponent <CollectibleBehavior>();
                    if (cb == null)
                    {
                        return;
                    }

                    if (cb.collectibleType == CollectibleType.Pollen)
                    {
                        cb.SendMessage("ControllerCollisionListener", new object[] { GetComponent <PlayerControl>(), 2 });
                        didDance = true;
                    }
                }
                else if (curTarget.CompareTag("Hive"))
                {
                    HiveManager hm = FindObjectOfType <HiveManager>();
                    hm.ActivateHiveDefence();
                    didDance = true;
                }
            }
            else
            {
                // Our third dance, Shock, isn't needed till level 3. I'm thinking this is some sort of AoE attack?
                // However, I don't know what the best way to trigger it would be, and if this `else` case is enough.

                // temp
                didDance = false;
            }

            if (didDance)
            {
                Instantiate(swarmVfx, curTarget.transform.position, Quaternion.identity);
                AudioSource.PlayClipAtPoint(danceMusic, transform.position, 1f);
                curPowerup     = PlayerPowerup.WaggleDance;
                powerupTimeout = waggleDanceDuration;
                waggleCollected--;
                gui.UpdateGUI(PlayerPowerup.WaggleDance, waggleCollected);
            }
        }
 void Start()
 {
     if (collectible != null)
     {
         behavior = collectible.AttachAbilityTo(gameObject);
     }
     else
     {
         Debug.LogWarning("No collectible config attached to CollectibleHandler");
         Destroy(gameObject, .1f);
     }
 }
    // Update is called once per frame
    public void AddSingleSound(CollectibleBehavior src)
    {
        if (isPlaying) return;
        if (isRecordingSolo) return;

        Sound s;
        s.timeStamp = 0;
        s.audioClip = src.m_audioSource.clip;
        s.lengthInBeats = src.lengthInBeats;

        SoundAction a = new SoundAction();
        a.type = 0;
        a.singleSound = s;

        composition.Add(a);
        Debug.Log("Stored a single sound");
    }
Esempio n. 7
0
 // Instead of OnCollisionEnter, this is the method that is called
 // when the CharacterController enters a collision. The event is triggered on the
 // CharacterController object only. However, the action to take place
 // is supposed ot be done by CollectibleBehavior. So we are sending a message
 // to the CollectibleBehavior to do the task
 private void OnControllerColliderHit(ControllerColliderHit hit)
 {
     if (hit.gameObject.CompareTag("Collectible"))
     {
         CollectibleBehavior cb = hit.gameObject.GetComponent <CollectibleBehavior>();
         if (cb == null)
         {
             return;
         }
         cb.SendMessage("ControllerCollisionListener", new object[] { player });
     }
     else if (hit.gameObject.CompareTag("Pesticide"))
     {
         PesticideBehavior pb = hit.gameObject.GetComponent <PesticideBehavior>();
         if (pb == null)
         {
             return;
         }
         pb.SendMessage("ControllerCollisionListener", new object[] { player });
     }
 }
Esempio n. 8
0
        public void InitBlock(IClassRegistryAPI instancer, ILogger logger, Block block, OrderedDictionary <string, string> searchReplace)
        {
            CollectibleBehaviorType[] behaviorTypes = Behaviors;

            if (behaviorTypes != null)
            {
                List <BlockBehavior>       blockbehaviors = new List <BlockBehavior>();
                List <CollectibleBehavior> collbehaviors  = new List <CollectibleBehavior>();

                for (int i = 0; i < behaviorTypes.Length; i++)
                {
                    CollectibleBehaviorType behaviorType = behaviorTypes[i];
                    CollectibleBehavior     behavior     = null;

                    if (instancer.GetCollectibleBehaviorClass(behaviorType.name) != null)
                    {
                        behavior = instancer.CreateCollectibleBehavior(block, behaviorType.name);
                    }

                    if (instancer.GetBlockBehaviorClass(behaviorType.name) != null)
                    {
                        behavior = instancer.CreateBlockBehavior(block, behaviorType.name);
                    }

                    if (behavior == null)
                    {
                        logger.Warning(Lang.Get("Block or Collectible behavior {0} for block {1} not found", behaviorType.name, block.Code));
                        continue;
                    }

                    if (behaviorType.properties == null)
                    {
                        behaviorType.properties = new JsonObject(new JObject());
                    }

                    try
                    {
                        behavior.Initialize(behaviorType.properties);
                    } catch (Exception e)
                    {
                        logger.Error("Failed calling Initialize() on collectible or block behavior {0} for block {1}, using properties {2}. Will continue anyway. Exception: {3}", behaviorType.name, block.Code, behaviorType.properties.ToString(), e);
                    }

                    collbehaviors.Add(behavior);
                    if (behavior is BlockBehavior bbh)
                    {
                        blockbehaviors.Add(bbh);
                    }
                }

                block.BlockBehaviors       = blockbehaviors.ToArray();
                block.CollectibleBehaviors = collbehaviors.ToArray();
            }

            if (CropProps != null)
            {
                block.CropProps = new BlockCropProperties();
                block.CropProps.GrowthStages           = CropProps.GrowthStages;
                block.CropProps.HarvestGrowthStageLoss = CropProps.HarvestGrowthStageLoss;
                block.CropProps.MultipleHarvests       = CropProps.MultipleHarvests;
                block.CropProps.NutrientConsumption    = CropProps.NutrientConsumption;
                block.CropProps.RequiredNutrient       = CropProps.RequiredNutrient;
                block.CropProps.TotalGrowthDays        = CropProps.TotalGrowthDays;
                block.CropProps.TotalGrowthMonths      = CropProps.TotalGrowthMonths;

                block.CropProps.ColdDamageBelow      = CropProps.ColdDamageBelow;
                block.CropProps.HeatDamageAbove      = CropProps.HeatDamageAbove;
                block.CropProps.DamageGrowthStuntMul = CropProps.DamageGrowthStuntMul;
                block.CropProps.ColdDamageRipeMul    = CropProps.ColdDamageRipeMul;


                if (CropProps.Behaviors != null)
                {
                    block.CropProps.Behaviors = new CropBehavior[CropProps.Behaviors.Length];
                    for (int i = 0; i < CropProps.Behaviors.Length; i++)
                    {
                        CropBehaviorType behaviorType = CropProps.Behaviors[i];
                        CropBehavior     behavior     = instancer.CreateCropBehavior(block, behaviorType.name);
                        if (behaviorType.properties != null)
                        {
                            behavior.Initialize(behaviorType.properties);
                        }
                        block.CropProps.Behaviors[i] = behavior;
                    }
                }
            }

            if (block.Drops == null)
            {
                block.Drops = new BlockDropItemStack[] { new BlockDropItemStack()
                                                         {
                                                             Code     = block.Code,
                                                             Type     = EnumItemClass.Block,
                                                             Quantity = NatFloat.One
                                                         } };
            }

            block.CreativeInventoryTabs = GetCreativeTabs(block.Code, CreativeInventory, searchReplace);

            foreach (BlockFacing facing in BlockFacing.ALLFACES)
            {
                if (SideAo != null && SideAo.ContainsKey(facing.Code))
                {
                    block.SideAo[facing.Index] = SideAo[facing.Code];
                }

                if (EmitSideAo != null && EmitSideAo.ContainsKey(facing.Code))
                {
                    if (EmitSideAo[facing.Code])
                    {
                        block.EmitSideAo |= (byte)facing.Flag;
                    }
                }

                if (SideSolid != null && SideSolid.ContainsKey(facing.Code))
                {
                    block.SideSolid[facing.Index] = SideSolid[facing.Code];
                }

                if (SideOpaque != null && SideOpaque.ContainsKey(facing.Code))
                {
                    block.SideOpaque[facing.Index] = SideOpaque[facing.Code];
                }
            }
        }