Example #1
0
        def _get():
            got = False
            prob = self.p.prisoners[str_id].prob + treasures_prob
            if prob >= random.randint(1, 100):
                # got it
                save_hero(self.char_id, self.p.prisoners[str_id].oid)
                got = True

                self.p.prisoners.pop(str_id)

                msg = protomsg.RemovePrisonerNotify()
                msg.ids.append(_id)
                publish_to_char(self.char_id, pack_msg(msg))
            else:
                self.p.prisoners[str_id].active = False

                msg = protomsg.UpdatePrisonerNotify()
                p = msg.prisoner.add()
                p_obj = self.p.prisoners[str_id]
                self._fill_up_prisoner_msg(p, _id, p_obj.oid, p_obj.prob, p_obj.active)

                publish_to_char(self.char_id, pack_msg(msg))

            self.p.save()
            return got
Example #2
0
    def prisoner_get(self, _id, treasures):
        str_id = str(_id)
        if str_id not in self.p.prisoners:
            raise SanguoException(errormsg.PRISONER_NOT_EXIST, self.char_id,
                                  "Prisoner Get", "{0} not exist".format(_id))

        if not self.p.prisoners[str_id].active:
            raise SanguoException(errormsg.PRISONER_NOT_ACTIVE, self.char_id,
                                  "Prisoner Get", "{0} not active".format(_id))

        treasures_prob = 0
        for tid in treasures:
            try:
                treasures_prob += TREASURES[tid].value
            except KeyError:
                raise SanguoException(errormsg.STUFF_NOT_EXIST, self.char_id,
                                      "Prisoner Get",
                                      "treasure {0} not exist".format(tid))

        using_stuffs = [(tid, 1) for tid in treasures]

        resource = Resource(self.char_id, "Prisoner Get")
        with resource.check(stuffs=using_stuffs):
            got = False
            prob = self.p.prisoners[str_id].prob + treasures_prob
            char = Char(self.char_id).mc
            vip_plus = VIP_FUNCTION[char.vip].prisoner_get
            prob += vip_plus
            if prob >= random.randint(1, 100):
                # got it
                save_hero(self.char_id, self.p.prisoners[str_id].oid)
                got = True

                self.p.prisoners.pop(str_id)

                msg = protomsg.RemovePrisonerNotify()
                msg.ids.append(_id)
                publish_to_char(self.char_id, pack_msg(msg))
            else:
                self.p.prisoners[str_id].active = False

                msg = protomsg.UpdatePrisonerNotify()
                p = msg.prisoner.add()
                p_obj = self.p.prisoners[str_id]
                self._fill_up_prisoner_msg(p, _id, p_obj.oid, p_obj.prob,
                                           p_obj.active)

                publish_to_char(self.char_id, pack_msg(msg))

            self.p.save()

        t = Task(self.char_id)
        t.trig(5)

        return got
Example #3
0
    def _abandon(self, _id, action=""):
        try:
            p = self.p.prisoners.pop(str(_id))
        except KeyError:
            raise SanguoException(errormsg.PRISONER_NOT_EXIST, self.char_id,
                                  action, "prisoner {0} not exist".format(_id))

        self.p.save()

        msg = protomsg.RemovePrisonerNotify()
        msg.ids.append(_id)
        publish_to_char(self.char_id, pack_msg(msg))
        return p
Example #4
0
        def _get():
            got = False
            prob = self.p.prisoners[str_id].prob + treasures_prob

            ae = ActivityEntry(self.char_id, 40008)
            if ae and ae.is_ok():
                prob += 80

            ae = ActivityEntry(self.char_id, 50005)
            if ae and ae.is_valid():
                _vip = ae.get_current_value(self.char_id)
                if _vip == 4:
                    prob += 30
                elif _vip == 5:
                    prob += 50
                elif _vip == 6:
                    prob += 60
                elif _vip >= 7:
                    prob += 100

            if prob >= random.randint(1, 100):
                # got it
                save_hero(self.char_id, self.p.prisoners[str_id].oid)
                got = True

                self.p.prisoners.pop(str_id)

                msg = protomsg.RemovePrisonerNotify()
                msg.ids.append(_id)
                publish_to_char(self.char_id, pack_msg(msg))
            else:
                self.p.prisoners[str_id].active = False

                msg = protomsg.UpdatePrisonerNotify()
                p = msg.prisoner.add()
                p_obj = self.p.prisoners[str_id]
                self._fill_up_prisoner_msg(p, _id, p_obj.oid, p_obj.prob, p_obj.active)

                publish_to_char(self.char_id, pack_msg(msg))

            self.p.save()
            return got