68 lines
2.0 KiB
PHP
68 lines
2.0 KiB
PHP
<?php
|
||
|
||
namespace common\models;
|
||
|
||
use yii\behaviors\TimestampBehavior;
|
||
use yii\db\ActiveRecord;
|
||
|
||
/**
|
||
* 宠物虚弱周期参与者。
|
||
*
|
||
* @property int $id
|
||
* @property int $be_user_id 被攻击玩家
|
||
* @property int $be_pet_id 被攻击宠物
|
||
* @property int $from_user_id 攻击玩家
|
||
* @property int $damage_total 累计伤害
|
||
* @property int $weak_until 虚弱周期结束时间,0 表示尚未进入虚弱
|
||
* @property int $active 是否当前虚弱周期有效
|
||
* @property int $created_at
|
||
* @property int $updated_at
|
||
*/
|
||
class PetBattleParticipant extends ActiveRecord
|
||
{
|
||
public function behaviors()
|
||
{
|
||
return [
|
||
TimestampBehavior::className(),
|
||
];
|
||
}
|
||
|
||
public function rules()
|
||
{
|
||
return [
|
||
['be_user_id', 'exist', 'targetClass' => '\common\models\User', 'targetAttribute' => 'id'],
|
||
['from_user_id', 'exist', 'targetClass' => '\common\models\User', 'targetAttribute' => 'id'],
|
||
['be_pet_id', 'exist', 'targetClass' => '\common\modules\pet\vo\Pet', 'targetAttribute' => 'id'],
|
||
|
||
[['damage_total', 'weak_until', 'active'], 'default', 'value' => 0],
|
||
[['damage_total', 'weak_until', 'active'], 'number', 'integerOnly' => true, 'min' => 0],
|
||
|
||
['created_at', 'default', 'value' => 0],
|
||
['updated_at', 'default', 'value' => 0],
|
||
];
|
||
}
|
||
|
||
public static function findCurrent($beUserID, $bePetID, $fromUserID)
|
||
{
|
||
return self::findOne([
|
||
'be_user_id' => $beUserID,
|
||
'be_pet_id' => $bePetID,
|
||
'from_user_id' => $fromUserID,
|
||
'weak_until' => 0,
|
||
]);
|
||
}
|
||
|
||
public static function hasActive($beUserID, $bePetID, $fromUserID, $now)
|
||
{
|
||
return self::find()
|
||
->where([
|
||
'be_user_id' => $beUserID,
|
||
'be_pet_id' => $bePetID,
|
||
'from_user_id' => $fromUserID,
|
||
'active' => 1,
|
||
])
|
||
->andWhere(['>', 'weak_until', $now])
|
||
->exists();
|
||
}
|
||
}
|