// If the wielder does not have a group ID that is compatible with this effect, discriminate
    private static GameEffectActorMethod CreateMethod_WeaponClassism(string tag, float damageScaleModifier)
    {
        return(delegate(EffectContext context, Actor targetActor)
        {
            Actor wielder = context.sourceActor;
            TagSet wielderTags = wielder.ActorDef.tags;
            WeaponBody sourceWeapon = context.sourceWeapon;
            damageScaleModifier *= 0.1f;

            // If this weapon is being used by an actor of the proper class...
            if (wielderTags.Contains(tag))
            {
                // Beneficiate...
                Debug.Log("You are the one! Applied damage scale modifier of " + damageScaleModifier.ToString());
                targetActor.ApplyHitDamage(context, 1f + damageScaleModifier);
            }
            // If this weapon is being used by an actor of the proper class...
            else
            {
                // Discriminate...
                Debug.Log("You are NOT the one. Applied damage scale modifier of " + damageScaleModifier.ToString());
                targetActor.ApplyHitDamage(context, 1f + (-damageScaleModifier));
            }
        });
    }
    public void Initialize(Dictionary <WeaponPart.WeaponStatType, float> weaponStats, WeaponBody body)
    {
        wpnBody = body;

        SetWeaponStats(weaponStats);

        muzzle        = body.muzzle;
        muzzleFlashFX = body.muzzleFX.GetComponent <ParticleSystem>();
    }
    void GenerateWeapon()
    {
        GameObject randomBody = GetRandomPart(bodyParts);
        GameObject insBody    = Instantiate(randomBody, Vector3.zero, Quaternion.identity);
        WeaponBody wpnBody    = insBody.GetComponent <WeaponBody>();

        WeaponPart barrel   = SpawnWeaponPart(barrelParts, wpnBody.barrelSocket);
        WeaponPart scope    = SpawnWeaponPart(scopeParts, wpnBody.scopeSocket);
        WeaponPart magazine = SpawnWeaponPart(magazineParts, wpnBody.magazineSocket);
        WeaponPart grip     = SpawnWeaponPart(gripParts, wpnBody.gripSocket);
        WeaponPart stock    = SpawnWeaponPart(stockParts, wpnBody.stockSocket);

        wpnBody.Initialize((WeaponBarrelPart)barrel, scope, stock, grip, magazine);

        prevWeapon = insBody;
    }
Esempio n. 4
0
 private static GameEffectWorldMethod CreateMethod_SpawnMinionThrow(string actorDefId, int level, float range, float amount)
 {
     return(delegate(EffectContext context)
     {
         Actor sourceActor = context.sourceActor;
         WeaponBody sourceWeapon = context.sourceWeapon;
         if (!LazySingletonBehavior <NetworkManager> .Instance.IsSimulationServer)
         {
             return;
         }
         SpawnMinions spawnMinions = sourceWeapon as SpawnMinions;
         for (int i = 0; i < (int)amount; i++)
         {
             Vector3 zero = Vector3.zero;
             Quaternion rotation = sourceActor.Rotation;
             if (!SpatialUtil.TryFindRandomSpotCircle(context.hitPoint, context.Radius, range, sourceActor.Height, out zero))
             {
                 Debug.Log("Couln't find valid spawn spot");
             }
             else
             {
                 LazySingletonBehavior <ActorManager> .Instance.Spawn(actorDefId, level, Actor.Faction.Player, /*context.hitPoint*/ zero, /*context.hitRot*/ rotation, delegate(Actor actor)
                 {
                     if (spawnMinions != null && spawnMinions.minionPrefab != null)
                     {
                         GameObject gameObject = spawnMinions.minionPrefab.Spawn(actor.transform);
                         Minion component = gameObject.GetComponent <Minion>();
                         if (component != null)
                         {
                             spawnMinions.AttachMinion(component);
                         }
                     }
                     Debug.Log(string.Concat(new object[]
                     {
                         "Spawned ",
                         actor.DebugName,
                         " at ",
                         actor.transform.position
                     }), actor);
                 });
             }
         }
     });
 }
    private static GameEffectWorldMethod CreateMethod_ShootGems(string itemDefId, int gemCost, int duration)
    {
        return(delegate(EffectContext context)
        {
            /* #########################################
             * Check if there is enough money to shoot
             #########################################*/
            if (!LazySingletonBehavior <NetworkManager> .Instance.IsSimulationServer)
            {
                return;
            }
            Actor wielder = context.sourceActor;
            if (wielder.IsRemoteSimulation)
            {
                return;
            }

            WeaponBody weapon = context.sourceWeapon;
            ActionDef action = context.sourceAction;
            int num = 0;
            if (weapon != null)
            {
                string ammoId = weapon.ItemDef.ammoId;
                num = weapon.GetAmmoUse(action);

                Inventory inventory = Inventory.Get(wielder.gameObject, true);
                int playerGems = inventory.GetCurrency("Gem1");
                // (For Ammo system) Checks if the weapon uses ammo and the rounds used are 0 or greater
                if (num >= 0 && !string.IsNullOrEmpty(ammoId))
                {
                    //Inventory inventory = Inventory.Get(wielder.gameObject);
                    if (inventory == null || !inventory.HasAmmo(ammoId, num))
                    {
                        //Debug.Log("Not playing NO AMMO animation.");
                        wielder.thisAnimator.SetTrigger(wielder.Body.thisAnimator.GetControlId("AttackEmpty"));
                        return;
                    }
                    if (num > 0)
                    {
                        inventory.RemoveAmmo(ammoId, num);
                    }
                    inventory.UpdateRangedSlot();
                }
                // (For consuming gems without an ammo system) if cost of gem projectile <= to player's bank account...
                if (gemCost <= playerGems)
                {
                    // remove cost of gem projectile
                    //Debug.Log("The Ambassador bribes its enemy to death.");
                    inventory.RemoveCurrency("Gem1", gemCost);

                    // Maybe give the amount returned by RemoveCurrency() to context.targetActor?
                }
                else
                {
                    // Uncomment the line below to trigger a NO AMMO animation if there isn't enough money.
                    // wielder.thisAnimator.SetTrigger(wielder.Body.thisAnimator.GetControlId("AttackEmpty"));
                    //Debug.Log("Ain't got no gems.");
                    return;
                }
            }

            /* #########################################
             * Handle the business of shooting
             #########################################*/
            ItemDef itemDef = LazySingletonBehavior <DataManager> .Instance.Items.Get(itemDefId);

            num = ((num <= 0) ? 1 : num);
            int count = 0;
            Vector3 position = weapon.transform.position;
            Quaternion rotation = weapon.transform.rotation;
            for (int i = 0; i < num; i++)
            {
                PrefabManager.InstantiatePrefab(itemDef.prefabName, false, null, position, rotation, delegate(GameObject go)
                {
                    Projectile component = go.GetComponent <Projectile>();
                    if (component == null)
                    {
                        //GameEffectManager.log.Error("Item \"" + itemDefId + "\" doesn't have a valid projectile prefab: " + go.name, go);
                        Debug.LogError("Item \"" + itemDefId + "\" doesn't have a valid projectile prefab: " + go.name, go);
                        go.Despawn();
                        return;
                    }
                    Vector3 zero = Vector3.zero;
                    float num2 = 1f;
                    if (count++ > 0)
                    {
                        zero = new Vector3((UnityEngine.Random.value - 0.5f) * num2, (UnityEngine.Random.value - 0.5f) * num2, (UnityEngine.Random.value - 0.5f) * num2);
                    }
                    go.SetActive(true);
                    component.Initialize(itemDef, wielder, weapon, action, wielder.TargetObject, duration, zero, Projectile.ProjectileType.Shoot, 0u);
                });
            }
        });
    }
Esempio n. 6
0
	protected bool RemoveWeaponComponent(WeaponComponent component, Transform toTrans) {
		if (!HasComponent(component))
			return false;
		if (component.Equals(body))
			body = null;
		component.DisassembleTo(toTrans);
		List<string> missingTypes = new List<string>();
		CheckIntegrity(ref missingTypes);
		return !HasComponent(component);
	}