[RenPy] 纯文本查看 复制代码
#1.物品的属性
init python:
list_item_xing=["天蚕","混世","龙虎","12","神","圣","阿星"]
list_item_ming=["刀","剑","棍","衣","鞋","头"]
rate2 = [1,1,1,1,1,1] #装备种类出现概率
#物品品阶字典
item_pinjie_dict={
"{color=#696969}破烂{/color}":1,
"{color=#F8F8FF}普通{/color}":2,
"{color=#32CD32}稀有{/color}":3,
"{color=#4B0082}史诗{/color}":4,
"{color=#9400D3}神器{/color}":5,
"{color=#FFFF00}圣器{/color}":6,
"{color=#FF0000}混沌{/color}":7,
}
#物品品阶列表
item_pinjie_list = [
"{color=#696969}破烂{/color}",
"{color=#F8F8FF}普通{/color}",
"{color=#32CD32}稀有{/color}",
"{color=#4B0082}史诗{/color}",
"{color=#9400D3}神器{/color}",
"{color=#FFFF00}圣器{/color}",
"{color=#FF0000}混沌{/color}",
]
rate1 = [2048,1024,256,64,16,4,1] #品质出现概率
list_item=[]#物品列表
dic_chuan_zhuangbei={} #已经穿了的装备
def random_index(rate):
#"""随机变量的概率函数"""
#
# 参数rate为list<int>
# 返回概率事件的下标索引
start = 0
index = 0
randnum = renpy.random.randint(1, sum(rate))
for index, scope in enumerate(rate):
start += scope
if randnum <= start:
break
return index
class Item(object):
"""物品基类"""
def __init__(self):
self.num = 0 #物品数量
self.smjg = 0 #售卖价格
self.gmjg = 0 #购买价格
class Zb_item(Item):
def __init__(self):
self.name = ""#名字
self.pinjie = "" #品阶
self.img = "" #图片
self.gjl = 0 #攻击力
self.fyl = 0 # 防御力
self.xljc = 0 # 血量加成
#self.smjg = smjg #售卖价格
#self.gmjg = 0 #购买价格
Item.__init__(self)
"""装备物品"""
#随机一个物品的属性
def suiji(self):
self.xing=renpy.random.choice(list_item_xing)
self.ming = list_item_ming[random_index(rate2)]
#self.ming=renpy.random.choice(list_item_ming)
self.name=self.xing+self.ming
self.pinjie=item_pinjie_list[random_index(rate1)] #随机品阶,item_pinjie_list[下标]
#self.pinjie=renpy.random.choice(list_item_pinjie)
if self.pinjie == "{color=#696969}破烂{/color}":
self.name = "{color=#696969}"+ self.name + "{/color}"
elif self.pinjie == "{color=#F8F8FF}普通{/color}":
self.name = "{color=#F8F8FF}"+ self.name + "{/color}"
elif self.pinjie == "{color=#32CD32}稀有{/color}":
self.name = "{color=#32CD32}"+ self.name + "{/color}"
elif self.pinjie == "{color=#4B0082}史诗{/color}":
self.name = "{color=#4B0082}"+ self.name + "{/color}"
elif self.pinjie == "{color=#9400D3}神器{/color}":
self.name = "{color=#9400D3}"+ self.name + "{/color}"
elif self.pinjie == "{color=#FFFF00}圣器{/color}":
self.name = "{color=#FFFF00}"+ self.name + "{/color}"
elif self.pinjie == "{color=#FF0000}混沌{/color}":
self.name = "{color=#FF0000}"+ self.name + "{/color}"
a = item_pinjie_dict[self.pinjie] #根据品阶,得出系数,然后计算攻击力、防御力等
if self.ming == "刀" or self.ming == "剑" or self.ming == "棍":
if self.ming == "刀":
self.img = ProportionalScale("images/items/weapon/dao.png",100,100)
elif self.ming == "剑":
self.img = ProportionalScale("images/items/weapon/jian.png",100,100)
elif self.ming == "棍":
self.img = ProportionalScale("images/items/weapon/gun.png",100,100)
self.gjl = pow(a,2) * renpy.random.randint(1,10) /2
self.fyl = 0
self.xljc = 0
self.smjg = 10 * pow(a,2)
elif self.ming == "头" or self.ming == "衣" or self.ming == "鞋":
if self.ming == "头":
self.img = ProportionalScale("images/items/accessory/tou.png",100,100)
elif self.ming == "衣":
self.img = ProportionalScale("images/items/accessory/yi.png",100,100)
elif self.ming == "鞋":
self.img = ProportionalScale("images/items/accessory/xie.png",100,100)
self.gjl = 0
self.fyl = pow(a,2) * renpy.random.randint(1,10) /2
self.xljc = pow(a,2) * renpy.random.randint(1,10) /2
self.smjg = 10 * pow(a,2)
#添加一个物品到list_item
def xin_suiji(self):
a = Zb_item()
#y = Zb_item()
a.suiji()
list_item.append(a)
#a = Zb_item()
aaa=Zb_item()#方天画戟
#城市物品随机并添加到商人物品列表中(哪个城市的哪个商人物品列表,数量)
def city_item_suiji(city_merchant_item_list,num):
while len(city_merchant_item_list) <= num:
a = Zb_item()
a.suiji()
a.num = 99
a.gmjg = 100 * pow(item_pinjie_dict[a.pinjie],2)#购买价格 = 100 * 品阶 * 品阶
city_merchant_item_list.append(a)
# def detective_dragged(drags, drop):
#
# if not drop:
# return
#
# store.detective = drags[0].drag_name
# store.city = drop.drag_name
#
# return True
#2.背包界面
screen beibao():
frame:
align(0.5,0.5)
xysize (560,420)
vbox:
hbox:
textbutton "关闭" action Call("sc_sy_jm", jm = "zjm")
$ max_beibao_num = zj.max_beibao_num[0]*zj.max_beibao_num[1]
text "[zj.beibao_num]/[max_beibao_num]"
# draggroup:
# drag:
vpgrid:
cols zj.max_beibao_num[0]
rows zj.max_beibao_num[1]
spacing 5
draggable True
mousewheel True
scrollbars "vertical"
align(0.5,0.5)
for x in list_item:
#use beibao1(i)
# draggroup:
# drag:
#align(0,0)
#drag_name "[x.name]"
#imagebutton auto "[x.img.imgname]_%s" action ShowTransient("item_duibi",wp=x,zj=zj,wuqi=dic_chuan_zhuangbei.get("武器"),toukui=dic_chuan_zhuangbei.get("头盔"),yifu=dic_chuan_zhuangbei.get("衣服"),xiezi=dic_chuan_zhuangbei.get("鞋子"))
button:
xysize (100, 120)
vbox:
add "[x.img.imgname]"
text "[x.name]" align(0.5,0.5)
action ShowTransient("item_duibi",wp=x,zj=zj,wuqi=dic_chuan_zhuangbei.get("武器"),toukui=dic_chuan_zhuangbei.get("头盔"),yifu=dic_chuan_zhuangbei.get("衣服"),xiezi=dic_chuan_zhuangbei.get("鞋子"))
# drag:
# drag_name "[x.name]"
# droppable False
#dragged detective_dragged
#xpos 100 ypos 100
#城市列表
screen city_name():
frame:
align(0.5,0.7)
hbox:
for y in city_list:
textbutton "[y.name]" action ShowTransient("city",cs = y),Hide("wq_store")
textbutton "返回" action Hide("city_name")
#城市里的人物或拥有的功能
screen city(cs):
frame:
align(0.9,0.5)
vbox:
textbutton "装备商人[cs.equip_merchant]" action ToggleScreen("zb_store",zb = cs.equip_list)
textbutton "杂货商人[cs.grocery_merchant]" action ToggleScreen("zb_store",zb = cs.grocery_list)
textbutton "返回" action Hide("city")
#textbutton "杂货商人[cs.grocery_businessman]" action ToggleScreen("zh_store",zh=cs.list_grocery)
#装备商店
screen zb_store(zb):
frame:
align(0.9,0.1)
vbox:
textbutton "关闭" action Hide("zb_store"),Hide("item")
for x in zb:
textbutton "[x.name] 数量:[x.num]" action ShowTransient("item",wp = x, type = "商店里的")
#物品信息
screen item(wp,type):
frame:
align(0.0,0.8)
hbox:
vbox:
text "[wp.name]"
text "品阶:[wp.pinjie]"
text "攻击力:[wp.gjl]"
text "防御力:[wp.fyl]"
text "血量:[wp.xljc]"
if type == "背包里的" or type == "穿戴着的":
text "售卖价格:[wp.smjg]"
elif type == "商店里的":
text "购买价格:[wp.gmjg]"
if type == "商店里的":
vbox:
textbutton "关闭" action Hide("item")
textbutton "购买" action Call("mai_zb",wp = wp)#wq1 = jlc.list_arms[0],list1 = jlc.list_arms
if type == "背包里的":
vbox:
textbutton "穿上" action Call("chuanshang",wp1 = wp)#wp1=list_item.index(wp))#获取当前物品的下标
textbutton "卖出" action Call("maichu",wp1=list_item.index(wp))
textbutton "融合" action Call("chuanshang")#没有做
if type == "穿戴着的":
vbox:
textbutton "卸下" action Call("xiexia",wp1 = wp)
#装备对比
screen item_duibi(wp,zj,wuqi,toukui,yifu,xiezi):
frame:
align(0.0,0.8)
#判断物品的部位,猪脚身上是否穿戴
if wp.ming == "剑" or wp.ming == "刀" or wp.ming == "棍" :
if zj.wuqi == "无":
use item(wp,"背包里的")
else:
hbox:
use item(wuqi,"穿戴着的")
use item(wp,"背包里的")
elif wp.ming == "头":
if zj.toukui == "无":
use item(wp,"背包里的")
else:
hbox:
use item(toukui,"穿戴着的")
use item(wp,"背包里的")
elif wp.ming == "衣":
if zj.yifu == "无":
use item(wp,"背包里的")
else:
hbox:
use item(yifu,"穿戴着的")
use item(wp,"背包里的")
elif wp.ming == "鞋":
if zj.xiezi == "无":
use item(wp,"背包里的")
else:
hbox:
use item(xiezi,"穿戴着的")
use item(wp,"背包里的")
#3.战斗胜利随机获取一件物品,并添加在背包界面
label tjwp:
#添加一个物品
#default beibao_num = 0
$ zj.beibao_num=len(list_item) #获取背包物品的数量
if zj.beibao_num < 25:
$ aaa.xin_suiji() #随机并添加
$ zj.beibao_num=len(list_item)
$ wb="获得{color=#00ff00}一件{/color}物品"
$ list_zdwb.append(wb)
if zj.beibao_num == 25 :
$ wb="物品满了,请尽快清理"
$ list_zdwb.append(wb)
else:
$ wb="物品满了,不再获得战利品"
$ list_zdwb.append(wb)
return
#4.物品的功能,比如买卖、装备卸下、融合等
# 穿装备并显示在装备界面
label chuanshang(wp1):
#$ item = list_item[wp1] #获取当前物品里的具体元素
$ zj.chuan_zhuangbei(wp1) #穿装备
$ zj.beibao_num=len(list_item)
call screen beibao
#卸下装备
label xiexia(wp1):
$ zj.xie_zhuangbei(wp1) #卸装备
$ zj.beibao_num=len(list_item)
call screen beibao
# 卖装备
label maichu(wp1):
$ item = list_item[wp1]
$ zj.money += item.smjg
$ del list_item[wp1] #删除当前物品
$ zj.beibao_num=len(list_item)
call screen beibao
#买装备
label mai_zb(wp):
#此时的wp1 = jlc.list_arms[0],city = jlc.list_arms
hide screen wq_sx
hide screen wq_store
$ Success_or_failure = zj.buy_item(wp)#购买是否成功
if Success_or_failure:
call screen beibao
#装备融合 3件同品质的升级为一个高一品质的
#穿装备
def chuan_zhuangbei(self,item):
#先判断是什么装备,再判断身上是否有装备
if item.ming == "剑" or item.ming == "刀" or item.ming == "棍":
if self.wuqi == "无":
self.wuqi = item.name
else:
self.wuqi = item.name
#卸下来
self.xia_fangju(dic_chuan_zhuangbei["武器"])
#添加到背包里
list_item.append(dic_chuan_zhuangbei["武器"])
#穿戴着的武器
dic_chuan_zhuangbei["武器"] = item
elif item.ming == "头":
if self.toukui == "无":
self.toukui = item.name
else:
self.toukui = item.name
self.xia_fangju(dic_chuan_zhuangbei["头盔"])
list_item.append(dic_chuan_zhuangbei["头盔"])
dic_chuan_zhuangbei["头盔"] = item
elif item.ming == "衣":
if self.yifu == "无":
self.yifu = item.name
else:
self.yifu = item.name
self.xia_fangju(dic_chuan_zhuangbei["衣服"]) #减去原有的装备属性
list_item.append(dic_chuan_zhuangbei["衣服"]) #背包添加原来穿戴的装备
dic_chuan_zhuangbei["衣服"] = item #穿装备
elif item.ming == "鞋":
if self.xiezi == "无":
self.xiezi = item.name
else:
self.xiezi = item.name
self.xia_fangju(dic_chuan_zhuangbei["鞋子"])
list_item.append(dic_chuan_zhuangbei["鞋子"])
dic_chuan_zhuangbei["鞋子"] = item
self.chuan_fangju(item)
self.chuan_wuqi(item)
list_item.remove(item)