//玩家获得宝藏(金币 宝石 等货币) public bool addTreasure(GameObject obj) { treasure_property objproperty = obj.GetComponent <treasure_property> (); int itemId = objproperty.ID; int amount = objproperty.Num; char_property pro = gameObject.GetComponent <char_property> (); switch (itemId) { default: break; case 200: //constant.getMapLogic ().bagAddGold (amount); pro.addGold(amount); break; case 201: //constant.getMapLogic().bagAddDiamond(amount); break; case 202: //constant.getMapLogic ().bagAddKey (amount); pro.addKey(amount); break; case 203: //constant.getMapLogic ().bagAddGoldenKey (amount); break; break; } return(true); }
//only being used by other scripts public void upgradeProperties(char_property property) { mbulletSpeed = baseBulletSpeed + property.AttackSpeed; mbulletRate = baseBulletRate - (baseBulletRate - 0.1f) * property.AttackRate / 10; mbulletDistance = baseBulletDistance + property.AttackDistance; mbulletDamage = baseBulletDamage + property.Damage * 5; }
override public void beAttackByBullet(GameObject obj) { //Debug.Log ("玩家被子弹攻击"); if (isWUDI()) { return; } bullet_property bulletProperty = obj.GetComponent <bullet_property>(); if (bulletProperty != null) { char_property charProperty = gameObject.GetComponent <char_property>(); charProperty.Hp = charProperty.Hp - bulletProperty.bulletDamage; if (bulletProperty.bulletknock != 0) { //Debug.Log (gameObject.name + "被击退.武器类型为:"); getKnockBack(charProperty, bulletProperty); } if (isDie()) { constant.getGameLogic().Die(); } if (bulletProperty.bulletDamage > 0) { setWUDI(); } } }
// Update is called once per frame void Update() { GameObject obj = GameObject.FindGameObjectWithTag(constant.TAG_PLAYER); if (obj == null) { return; } char_property pro = obj.GetComponent <char_property> (); //Debug.Log ("pro hp:" + pro.MaxHp + "," + pro.Hp); int totalHp = pro.MaxHp; if (mHps.Count > pro.MaxHp) { for (int i = mHps.Count - 1; i >= pro.MaxHp; --i) { GameObject hpObj = mHps[i]; mHps.Remove(hpObj); Destroy(hpObj); } } else if (mHps.Count < pro.MaxHp) { int oldnum = mHps.Count; int num = pro.MaxHp - mHps.Count; for (int i = 0; i < num; ++i) { Vector3 v = getPosition(i + oldnum); //GameObject hpObj = (GameObject)Instantiate(Resources.Load(hpPath),v,Quaternion.identity); GameObject prefab = Resources.Load <GameObject> (hpPath); GameObject hpObj = Instantiate(prefab) as GameObject; hpObj.transform.parent = this.gameObject.transform; hpObj.transform.localPosition = v; mHps.Add(hpObj); } } //Component charProperty = obj.GetComponent<"char_property">(); //int hp = charProperty.getHp(); int hp = pro.Hp; for (int i = 0; i < totalHp; ++i) { GameObject hpSprObj = mHps[i]; // GameObject.Find("hp_child" + (i+1)); tk2dSprite spr = hpSprObj.GetComponentInChildren <tk2dSprite>(); if (i < hp) { spr.SetSprite(spr.GetSpriteIdByName("heart_full")); } else { spr.SetSprite(spr.GetSpriteIdByName("heart_empty")); } } }
public void setWUDI() { char_property pro = this.gameObject.GetComponent <char_property> (); mHurtTime = pro.HurtTime; robotAniManager mgr = gameObject.GetComponent <robotAniManager> (); mgr.playWUDI(); }
//在玩家背包删除旧的武器图标 public bool changeWeaponIcon(GameObject obj) { item_property itemProperty = obj.GetComponent <item_property>(); int itemId = itemProperty.ID; //constant.getMapLogic().bagAddIcon(itemId); char_property charProperty = gameObject.GetComponent <char_property>(); charProperty.Weapon = constant.getItemFactory().getItemTemplate(itemId); return(true); }
void OnTriggerStay(Collider other) { //判断是的是否开始工作 if (doDamage) { bulletPro = gameObject.GetComponent <bullet_property>(); //主角发出的子弹 if (bulletPro.BattleType == constant.BattleType.Player) { enemylogic logic = other.gameObject.GetComponent <enemylogic> (); if (logic) { if (!enemyDictionary.ContainsKey(other.name)) { enemyDictionary.Add(other.name, 99); } if (enemyDictionary[other.name] >= bulletPro.bulletDamageRate) { constant.getMapLogic().triggerEnter(other.gameObject, this.gameObject); //gameObject.GetComponent<bulletAniManager> ().buuletHit = true; //vibrate.joystickVibrate(0.2f,1,1); enemyDictionary[other.name] = 0; } else { //Debug.Log ("伤害间隔中,无法造成伤害 debug_cTime = " + cTime); } } } //敌人发出的子弹 if (bulletPro.BattleType == constant.BattleType.Enemy) { char_property logic = other.gameObject.GetComponent <char_property> (); if (logic) { if (cTime >= bulletPro.bulletDamageRate) { constant.getMapLogic().triggerEnter(other.gameObject, this.gameObject); //gameObject.GetComponent<bulletAniManager> ().buuletHit = true; //vibrate.joystickVibrate(0.2f,1,1); cTime = 0; } else { //Debug.Log ("伤害间隔中,无法造成伤害 debug_cTime = " + cTime); } } } } }
//子弹特殊效果强化 public bool enforceWeapon(GameObject obj) { bulletEnforce_Property bulletEnforcePro = obj.GetComponent <bulletEnforce_Property> (); bulletSpeStruct bulletSpe = bulletEnforcePro.bulletSpe; char_property charProperty = gameObject.GetComponent <char_property> (); if (charProperty) { charProperty.enforceBullet(bulletSpe); return(true); } Debug.Log("子弹效果无法强化,请检查系统!"); return(false); }
//在玩家背包里留下物品的图标 public bool putInBag(GameObject obj, bool checkBag) { if (checkBag) { return(false); } item_property itemProperty = obj.GetComponent <item_property>(); int itemId = itemProperty.ID; //constant.getMapLogic().bagAddIcon(itemId); char_property charProperty = gameObject.GetComponent <char_property>(); charProperty.addItem(constant.getItemFactory().getItemTemplate(itemId)); return(true); }
//玩家是否失败 public bool isDie() { char_property charProperty = gameObject.GetComponent <char_property>(); if (charProperty.Hp <= 0) { if (charProperty.ExtarLifes > 0) { reBirth(charProperty); return(false); } return(true); } return(false); }
// Use this for initialization void Awake() { recoverTime = 40; mRecoverTime = recoverTime + Random.Range(-5, 6); //Debug.Log ("恢复之心下次恢复时间: " + mRecoverTime); tempTimer = 0; player = gameObject.GetComponentInParent <char_property>(); if (player) { Debug.Log("恢复之心开始启动"); } else { Debug.Log("恢复之心不在玩家身上"); } }
//玩家获得武器道具,更换武器 public bool switchWeapon(GameObject obj) { weaponItem_property weaponProperty = obj.GetComponent <weaponItem_property> (); char_property playerProperty = gameObject.GetComponent <char_property> (); robotWeaponSwitch weaponSwitch = gameObject.GetComponent <robotWeaponSwitch> (); if (weaponSwitch.switchWeapon(weaponProperty)) { if (playerProperty) { playerProperty.upgradeShootProperties(); } return(true); } Debug.Log("error: 无法在玩家身上找到相应的武器系统!"); return(false); }
//检查恢复恐惧效果 override public void checkScaredRecover(float deltaTime) { char_property charProperty = gameObject.GetComponent <char_property> (); if (charProperty.scared == true) { float scaredRecoverTime = charProperty.scaredRecoverTime; if (deltaTime >= scaredRecoverTime) { //Debug.Log (deltaTime + "--" + scaredRecoverTime + ": " + this.name + "解除恐惧"); charProperty.scared = false; } } else { deltaTime_scared = 0; } }
//恢复玩家生命或者能量 public bool recoverChar(GameObject obj) { int graped = 0; recover_Property recoverProperty = obj.GetComponent <recover_Property>(); char_property charProperty = gameObject.GetComponent <char_property>(); if (recoverProperty) { if (recoverProperty.extarLifes != 0) { charProperty.ExtarLifes += recoverProperty.extarLifes; graped += 1; } if (recoverProperty.recoverHp > 0 && charProperty.Hp < charProperty.MaxHp) { int hp = charProperty.Hp + recoverProperty.recoverHp; if (hp > charProperty.MaxHp) { hp = charProperty.MaxHp; } charProperty.Hp = hp; graped += 1; } if (recoverProperty.recoverNp > 0 && charProperty.Hp < charProperty.MaxNp) { int hp = charProperty.Np + recoverProperty.recoverNp; if (hp > charProperty.MaxNp) { hp = charProperty.MaxNp; } charProperty.Hp = hp; graped += 1; } } if (graped > 0) { return(true); } return(false); }
//强加玩家属性 public bool enforceChar(GameObject obj) { int graped = 0; enforce_Property enforceProperty = obj.GetComponent <enforce_Property>(); char_property charProperty = gameObject.GetComponent <char_property>(); if (enforceProperty) { charProperty.upgradePlayerProperty(enforceProperty); graped += 1; } if (graped > 0) { return(true); } return(false); }
//玩家购买道具 public bool buyItem(GameObject shoptable) { char_property charproperty = gameObject.GetComponent <char_property> (); buyItem_Property buyproperty = shoptable.GetComponent <buyItem_Property> (); int itemId = buyproperty.mID; if (itemId == 0) { Debug.Log("道具已售罄"); return(false); } int itemPrice = buyproperty.itemPrice; int charGold = charproperty.Gold; if (charGold >= itemPrice) { string itemPath = itemfactory.getInstance().getItemTemplate(itemId).PrefabPath; if (itemPath != "") { Vector3 itemTempPos = new Vector3(0, 0, -100); GameObject itemClone = (GameObject)Instantiate(Resources.Load(itemPath), itemTempPos, Quaternion.identity); if (grapItem(itemClone)) { GameObject.Destroy(itemClone); } else { Debug.Log("金币足够,其他原因无法购买道具"); GameObject.Destroy(itemClone); return(false); } } Debug.Log("剩余金钱: " + (charGold - itemPrice) + " = " + charGold + " - " + itemPrice); charproperty.Gold = charGold - itemPrice; return(true); } else { Debug.Log("金币不足"); return(false); } }
void OnTriggerEnter(Collider other) { if (!bulletDie) { if (other.gameObject.layer == 8) { hitWall(); return; } if (other.gameObject.tag == "Wall") { hitWall(); return; } if (other.gameObject.tag == "Door") { hitWall(); return; } if (bulletProperty.BattleType == constant.BattleType.Player) { enemy_property enemyPro = other.gameObject.GetComponent <enemy_property> (); if (enemyPro) { //Debug.Log("子弹击中怪物."); hitEnemies(); } } if (bulletProperty.BattleType == constant.BattleType.Enemy) { char_property charPro = other.gameObject.GetComponent <char_property> (); if (charPro) { Debug.Log("子弹击中玩家."); hitEnemies(); } } } }
//player beattacked must edit in next 玩家收到伤害 将要修改 override public void beAttack(GameObject obj) { Debug.Log("char beAttack"); if (isWUDI()) { return; } enemy_property enemyProperty = obj.GetComponent <enemy_property>(); if (enemyProperty != null) { char_property charProperty = gameObject.GetComponent <char_property>(); charProperty.Hp = charProperty.Hp - 1; if (isDie()) { constant.getGameLogic().Die(); } setWUDI(); } }
public void getKnockBack(char_property player, bullet_property bullet) { }
//UPGRADE SHOOTER PROPERTY FROM CHARACTER PROPERTY 更新武器的属性 当人物属性变化时 public void upgradeProperties(char_property property) { mcoldDown = coldDown - property.AttackRate * 0.1f; laserRate = preTime + flyingTime + mcoldDown; mbulletDamage = laserDamage + property.Damage * 5; }
//主角重生 public void reBirth(char_property charProperty) { charProperty.ExtarLifes = charProperty.ExtarLifes - 1; charProperty.Hp = charProperty.MaxHp; }
//背包增加普通钥匙 public void bagAddKey(int amount, GameObject player) { char_property charProperty = player.GetComponent <char_property> (); charProperty.addKey(amount); }
public void dropWeapon() { char_property charProperty = gameObject.GetComponent <char_property>(); itemtemplate oldWeapon = charProperty.Weapon; }